谷歌Chrome浏览器的用户参考文献window.open

编程入门 行业动态 更新时间:2024-10-28 22:24:33
本文介绍了谷歌Chrome浏览器的用户参考文献window.open的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在想这个问题,但是当我尝试引用一个窗口时,我打开了句柄总是未定义。

它是值得注意的是,这是在 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

本文发布于:2023-10-09 10:45:23,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参考文献   浏览器   用户   Chrome   谷歌

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!