gpt4 book ai didi

javascript - 关注 $window 打开的窗口

转载 作者:行者123 更新时间:2023-11-28 05:54:11 27 4
gpt4 key购买 nike

我必须从 Angular 应用程序启动一系列窗口。我希望能够让用户单击主页上的按钮以使该窗口重新成为焦点。通常我会在 javascript 中使用类似以下内容来执行此操作:

//Launch the window
newWindow = window.open("http://test.com",'windowName','_blank');
//Then later, to bring the window back into focus
myWindow.focus();

在 Angular 中,我可以按如下方式启动窗口(使用 $window 服务):

$window.open("http://test.com ",'newWindow','_blank');

如何使用 $window 服务使该窗口重新成为焦点?

非常感谢。

最佳答案

与使用窗口的方式相同。

$window 服务 equals to window$window 优于 window 全局,以使其在测试中可模拟。

The reference明确指出:

A reference to the browser's window object. While window is globally available in JavaScript, it causes testability problems, because it is a global variable. In angular we always refer to it through the $window service, so it may be overridden, removed or mocked for testing.

关于javascript - 关注 $window 打开的窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37839342/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com