简体   繁体   English

JavaScript 带多个弹出窗口

[英]JavaScript with multiple popups

I am trying to open a new pop up for my application, and each popup has a window name.我正在尝试为我的应用程序打开一个新的弹出窗口,每个弹出窗口都有一个 window 名称。 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.请建议如何使用 go。

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");

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, eg通常的策略是保存对每个 window 的引用,然后检查它是否仍然打开并可供以后重复使用,例如

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.如果您想打开多个 windows,那么您将需要一种策略来跟踪您要将特定资源加载到哪一个。

You may find the HTML5 window (creating and navigating contexts by name) and MDN window.open documentation useful.您可能会发现HTML5 window (按名称创建和导航上下文)和MDN window.open文档很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM