Unique popup window using window.open in an iframe
我有一个带窗口打开的iFrame(
iFrame位于单页应用程序中,并托管在另一台服务器中。
每次刷新或更改页面时,都返回IFrame页面,然后尝试启动相同的
-
销毁后,iFrame
window.open 的行为是否如此? - 我尝试在本地运行iFrame源,即使刷新后,打开的窗口也可以正常运行。
- 我在IE,Firefox和Chrome中尝试过,但返回的行为相同。
更新:
Mike通过为iFrame源添加了沙箱属性,成功解决了Webkit浏览器的问题。现在,
但是,Mike仍然对Firefox没有运气。如果有人可以为此解决问题,将不胜感激。
以下视频中具有带框盒装属性的iFrame的Webkit浏览器行为。
See that the parent, even when refreshed still can detect that there is an already opened popup of the same name.
https://youtu.be/z5_xXRjY8Ow
以下视频中具有带盒装属性的iFrame的Firefox行为。
When the parent window is refreshed, the browser could not detect the already opened popup and creates another instance of the pop up with the same
window.name .
https://youtu.be/uHaDveW1Sd0
有没有解决方法可以使Firefox像Webkit浏览器一样运行?
更新:
迈克发现在window.open中使用空白网址在firefox中表现正常。
但是仍然如何解决这个问题。
更新:
这是约翰尼! er Mike是另一个测试用例。
尝试使用Webkit浏览器和Firefox。
打开弹出窗口后,刷新页面,然后打开另一个弹出窗口
webkit浏览器将只有一个实例,但是firefox将创建一个新实例。
https://bug1295839.bmoattachments.org/attachment.cgi?id=8782242
我在您的代码中看到了几个问题:
您正在调用嵌套在另一个函数内的函数以关闭窗口,该函数永远不会被触发,因为此时无法调用父函数。
1 2 3 4 5 6 | function openWin(){ /* code */ } function closeWin(){ /* code */ } |
为了确保浏览器兼容以关闭窗口,我强烈建议在父窗口的生成的弹出窗口中设置并调用一个可注入函数
注入函数的示例:
1 2 3 4 5 6 7 8 9 | myWindow.document.write( "<p> This is 'myWindow' </p>" +"" +"function closeWindow()\\{" // sample injected function +"window.close();" +"\\}<\\/script>" ); |
完整示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <!DOCTYPE html> <html> <body> <button onclick="openWin()">Open"myWindow"</button> <button onclick="closeWin()">Close"myWindow"</button> var myWindow; function openWin() { myWindow = window.open("","myWindow","width=200,height=100"); myWindow.document.write( "<p> This is 'myWindow' </p>" +"" +"function closeWindow()\\{" // sample injected function +"window.close();" +"\\}<\\/script>" ); } function closeWin() { if(!myWindow.closeWindow) { setTimeout(closeWin,1000); // repeat if function not found } else { myWindow.closeWindow(); } } </body> </html> |
好像是一个镀铬的虫子
https://bugzilla.mozilla.org/show_bug.cgi?id=1295839
https://bugs.chromium.org/p/chromium/issues/detail?id=640620blockquote>