具有多个弹出窗口的 JavaScript

发布于 2024-12-03 01:36:25 字数 832 浏览 0 评论 0原文

我正在尝试为我的应用程序打开一个新的弹出窗口,每个弹出窗口都有一个窗口名称。假设如果用户关闭弹出窗口,他可以打开具有相同名称的弹出窗口,否则应显示现有的弹出窗口。

我编写了下面的代码来执行此操作,但是如果用户关闭它,则不会打开弹出窗口,否则会打开一个新的弹出窗口。请建议如何处理这个问题。

d='javascript:if(document.getElementsByTagName("*").length>0&&document.getElementsByTagName("body")[0].innerHTML!=""&&!confirm("You are about to navigate to home page Do you want to do that ? "))
{opener.display2WindowHelp();}
else
{window.location.replace("${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}'+d+'");
}';
b= window.open(d,"_spor_window_"+a+window.location.hostname.replace(/\./g,""),"menubar=no,scrollbars=yes,height="+screen.availHeight+",width="+screen.availWidth+",left=0,top=0,resizable=yes,toolbar=no,location=no,status=no");

I am trying to open a new pop up for my application, and each popup has a window name. Suppose if the user closes the popup he can open the popup with same name, else the existing pop up should be displayed.

I wrote the below code to do that, but this is not opening a popup if the user closes it else its opening a new popup. Please suggest how can go with this.

d='javascript:if(document.getElementsByTagName("*").length>0&&document.getElementsByTagName("body")[0].innerHTML!=""&&!confirm("You are about to navigate to home page Do you want to do that ? "))
{opener.display2WindowHelp();}
else
{window.location.replace("${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}'+d+'");
}';
b= window.open(d,"_spor_window_"+a+window.location.hostname.replace(/\./g,""),"menubar=no,scrollbars=yes,height="+screen.availHeight+",width="+screen.availWidth+",left=0,top=0,resizable=yes,toolbar=no,location=no,status=no");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我爱人 2024-12-10 01:36:25

如果您需要打开任何弹出窗口,可能有更好的方法来满足您的要求。如果您要打开多个弹出窗口,那么您的设计需要彻底审查(考虑您的工作流程以及选项卡式界面是否是更好的选择)。

通常的策略是保存对每个窗口的引用,然后检查它是否仍然打开并可供以后重复使用,例如,

var popWin;

function openWindow(url) {
  var windowName = '...';
  var features = '...';

  if (!popWin || popWin.closed) {
    popWin = window.open(url, windowName, features);

  } else {
    popWin.location.href = url;
  }
}

如果您想打开多个窗口,那么您将需要一种策略来跟踪要加载的窗口特定资源。

您可能会发现 HTML5 窗口(按名称创建和导航上下文)和 MDN window.open 文档很有用。

If you need to open any popups, there are likely better ways to meet your requirements. If you are opening several popups, then your design needs a thorough review (consider your workflow and whether a tabbed interface is a better option).

The usual strategy is to save a reference to each window, then check if it's still open and available for re-use later, e.g.

var popWin;

function openWindow(url) {
  var windowName = '...';
  var features = '...';

  if (!popWin || popWin.closed) {
    popWin = window.open(url, windowName, features);

  } else {
    popWin.location.href = url;
  }
}

If you want to have multiple windows open, then you will need a strategy for tracking which one you want to load a particular resource into.

You may find the HTML5 window (creating and navigating contexts by name) and MDN window.open documentation useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文