我一直在想这个问题,但是当我尝试引用一个窗口时,我打开了句柄总是未定义。
它是值得注意的是,这是在 userscript 中使用的,这里是问题片段:
var donateWindow; // ######################################## ############################## //#显示捐款弹出窗口并打开一个窗口到贝宝网站 // ############################################## ######################## function showDonateWindow() { if(window.confirm(Question here )) { if(!(typeof(donateWindow)=='undefined'|| donateWindow.closed))window.donateWindow.close(); window.donateWindow = window.open(somesite/,tabName); } }对此非常感激。这看起来不管我做了什么,window.open返回值undefined。
我的目标是显示一个弹出窗口,但如果已经打开它应该刚刚取代了旧的。这在FF中可以正常工作,但在我的生活中,我无法在Chrome中使用它。
试图在打开新窗口之前关闭现有窗口?你不需要这样做。如果你打开它时只是使用相同的窗口名称,它将会替换现有的窗口。 p>
这意味着您不需要查看是否有打开的窗口。
function showDonateWindow() { if(window.confirm(Question here)) { window.open(somesite /, donateWindowName); } }
I have been trying to figure this one out for a while, but when I try to reference a window that I opened the handle is always undefined.
It is worth noting that this is being used in a userscript and here is the snippet in question:
var donateWindow; // ###################################################################### // # Show the donation popup and open a window to paypal site // ###################################################################### function showDonateWindow() { if (window.confirm("Question here")) { if (! (typeof(donateWindow) == 'undefined' || donateWindow.closed)) window.donateWindow.close(); window.donateWindow = window.open("somesite/","tabName"); } }Any help on this would be very appreciated. It would seem no matter what I do window.open returns the value "undefined".
My goal is to have a popup shown, but if one is already open it should just replaced the old one. This works as expected in FF, but for the life of me I can not get it going in Chrome.
解决方案Why are you trying to close existing window before open a new one? you don't need to do that.
if you just use the same name for window when you open it, it will replace the existing one if there is.
this means you don't need to look for if there is an opened window.
function showDonateWindow() { if (window.confirm("Question here")) { window.open("somesite/","donateWindowName"); } }
更多推荐
谷歌Chrome浏览器的用户参考文献window.open
发布评论