爪哑脚本 |检查是否已打开具有特定 URL 的窗口
Javascript | Check if a windows with specific URL already is opened
此函数显示/ticket.html 弹出窗口。
我需要在窗口是否已经打开之前检查。如果是,请取消新的打开。
怎么能做到这一点呢?
function popitup() {
newwindow=window.open("ticket.html","_blank","toolbar=yes,scrollbars=yes, resizable=yes, top=500, left=500, width=730, height=700");
newwindow.moveTo(350,150);
if (window.focus)
{
newwindow.focus()
}
}
问候
打开窗口时,可以保存对窗口的引用。window.open
方法返回一个windowObjectReference
。
使用此引用,您可以检查窗口是否已关闭(closed
属性,布尔值),或者只是窗口是否为 null(window
属性,它将是一个Window
对象或 null,如果关闭)。
简单的例子:
// Open the pop-up and save the reference.
var windowObjRef = window.open('ticket.html');
// Verification, alternative 1. You may encapsulate this in a method.
if (windowObjRef.closed) {
// The window is closed.
else {
// The window is still open.
}
// Verification, alternative 2. You may encapsulate this in a method.
if (windowObjRef.window) {
// The window is still open.
else {
// The window is closed.
}
参考: https://developer.mozilla.org/en-US/docs/Web/API/Window
我是javascript的新手。我找到了一个提供以下代码的网站。但它仅提供有关窗口是否更早创建的信息。
function myOpenWindow(winURL, winName, winFeatures, winObj)
{
var theWin; // this will hold our opened window
// first check to see if the window already exists
if (winObj != null)
{
// the window has already been created, but did the user close it?
// if so, then reopen it. Otherwise make it the active window.
if (!winObj.closed) {
winObj.focus();
return winObj;
}
// otherwise fall through to the code below to re-open the window
}
// if we get here, then the window hasn't been created yet, or it
// was closed by the user.
theWin = window.open(winURL, winName, winFeatures);
return theWin;
}
此外,访问其他选项卡的内容也可能对用户的隐私造成攻击。
相关文章:
- 按下一个HTML按钮,该按钮使用一个功能在同一个新窗口中打开URL
- asp.net MVC,重定向到视图,视图打开新窗口到外部url,它'It’’’’我们被当成一种风景
- javascript在退出时打开窗口url
- 如何在新选项卡中而不是在新窗口中打开URL
- 如何在传单.js中显示每个choropleth弹出窗口的唯一名称和URL
- 如何在 Node-Webkit 的同一窗口中打开 URL
- 表单按钮在同一窗口中打开新的URL
- 在Chrome中的适当选项卡/窗口中打开URL
- 如何使模式窗口打开动态内容并更改url
- 在d3.js中单击URL为的节点时无法打开弹出窗口
- 如何在新窗口中打开url
- 通过程序在窗口中打开一个外部URL,链接会附加到网站上
- 使用自定义内容而不是url创建弹出窗口
- Javascript;html:有没有一种方法可以找到一个顶级的命名窗口(或选项卡)并将其带到前台,而不是将url加载到
- 为什么我的URL在JavaScript中被调用为弹出窗口
- 如何发布到URL并打开一个新窗口以显示pdf格式的响应
- 使用Crossrider查找窗口并导航到URL
- 从文本框中附加url,然后使用javascript打开新窗口
- 如何在扩展上显示url的内容's弹出窗口
- 加载的NW JS窗口不会触发URL,但会从本地文件触发