简体   繁体   English

在JavaScript中检测浏览器窗口

[英]Detect browser window in javascript

I'm a newbie in javascript and I've to do the following operation: I have an asp .net application which load in a new window browser another content. 我是javascript新手,必须执行以下操作:我有一个.net应用程序,它将在新窗口浏览器中加载其他内容。

Through javascript, I need to refresh the popup which i opened before, but I don't know how I can find that new window. 通过javascript,我需要刷新之前打开的弹出窗口,但是我不知道如何找到该新窗口。

I tried a simple window.location.reload(true); 我尝试了一个简单的window.location.reload(true); but this will cause a refresh only of the main browser window which launched the popup. 但这将仅刷新启动弹出窗口的主浏览器窗口。 Instead my intent is to refresh only the popup window. 相反,我的意图是仅刷新弹出窗口。

If you open the window with window.open() , grab its return value. 如果使用window.open()打开窗口,则获取其返回值。 That's a reference to the window object of the popup. 这是对弹出窗口对象的引用。 From there you can call location.reload() . 从那里可以调用location.reload() For example, this will open a window and then reload it again: 例如,这将打开一个窗口,然后再次重新加载它:

var popup = window.open('/somepage');
popup.location.reload(true);

When you open the window, give it a name (or store the return value of the window). 打开窗口时,为其命名(或存储窗口的返回值)。 Then, instead of window.location.reload , call name.location.reload where name is the name you gave the window. 然后,而不是window.location.reload ,调用name.location.reload ,其中name是您为窗口指定的名称。

Store a reference to your popup window and then instead of calling the location.reload() function on your main window, call it on the popup window, like this: 存储对弹出窗口的引用,然后在弹出窗口上调用它,而不是在主窗口上调用location.reload()函数:

var myNewWindow = window.open(...);
myNewWindow.location.reload(true);

Are you creating the new window using Javascript? 您是否正在使用Javascript创建新窗口? if you are using window.open() , that function returns a reference to the new window, So you can do something like this: 如果您使用window.open() ,那么该函数将返回对新窗口的引用,因此您可以执行以下操作:

var newWin = window.open();
newWin.location.reload(true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM