<i id='dgG21'><tr id='dgG21'><dt id='dgG21'><q id='dgG21'><span id='dgG21'><b id='dgG21'><form id='dgG21'><ins id='dgG21'></ins><ul id='dgG21'></ul><sub id='dgG21'></sub></form><legend id='dgG21'></legend><bdo id='dgG21'><pre id='dgG21'><center id='dgG21'></center></pre></bdo></b><th id='dgG21'></th></span></q></dt></tr></i><div id='dgG21'><tfoot id='dgG21'></tfoot><dl id='dgG21'><fieldset id='dgG21'></fieldset></dl></div>
<tfoot id='dgG21'></tfoot>

      1. <small id='dgG21'></small><noframes id='dgG21'>

        <legend id='dgG21'><style id='dgG21'><dir id='dgG21'><q id='dgG21'></q></dir></style></legend>
          <bdo id='dgG21'></bdo><ul id='dgG21'></ul>

        JavaScript window.open 仅当窗口不存在时才打开

        JavaScript window.open only if the window does not already exist(JavaScript window.open 仅当窗口不存在时才打开)

          1. <i id='EN3DL'><tr id='EN3DL'><dt id='EN3DL'><q id='EN3DL'><span id='EN3DL'><b id='EN3DL'><form id='EN3DL'><ins id='EN3DL'></ins><ul id='EN3DL'></ul><sub id='EN3DL'></sub></form><legend id='EN3DL'></legend><bdo id='EN3DL'><pre id='EN3DL'><center id='EN3DL'></center></pre></bdo></b><th id='EN3DL'></th></span></q></dt></tr></i><div id='EN3DL'><tfoot id='EN3DL'></tfoot><dl id='EN3DL'><fieldset id='EN3DL'></fieldset></dl></div>
              <bdo id='EN3DL'></bdo><ul id='EN3DL'></ul>

              <tfoot id='EN3DL'></tfoot>
            • <legend id='EN3DL'><style id='EN3DL'><dir id='EN3DL'><q id='EN3DL'></q></dir></style></legend>
              • <small id='EN3DL'></small><noframes id='EN3DL'>

                  <tbody id='EN3DL'></tbody>
                  本文介绍了JavaScript window.open 仅当窗口不存在时才打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个应用程序,在单击链接时会打开一个新窗口.这会生成一个包含 Java 小程序的页面.我遇到的问题是单击相同的链接会重新加载页面,从而重置 Java 应用程序.有什么办法可以捕获这个吗?两种可以接受的解决方案是:

                  I have an application that opens a new window on clicking a link. This spawns a page that holds a Java applet. The problem I am having is that clicking the same link reloads the page, which resets the Java application. Is there any way to trap this? Two solutions that would be acceptable are:

                  1. 允许从点击处理程序打开多个窗口
                  2. 如果窗口已经打开,则忽略后续请求

                  为成为 Javascript 新手而道歉 - 这并不是我的主要工作.

                  Apologies for being a Javascript newbie - it's not really my main thing.

                  附加到处理程序的代码是

                  The code attached to the handler is

                  function launchApplication(l_url, l_windowName)
                  {
                    var l_width = screen.availWidth;
                    var l_height = screen.availHeight;
                  
                    var l_params = 'status=1' +
                                   ',resizable=1' +
                                   ',scrollbars=1' +
                                   ',width=' + l_width +
                                   ',height=' + l_height +
                                   ',left=0' +
                                   ',top=0';
                  
                    winRef = window.open(l_url, l_windowName, l_params);
                    winRef.moveTo(0,0);
                    winRef.resizeTo(l_width, l_height);
                  }
                  

                  感谢您的回复 - 我稍微修改了建议,以便可以通过该函数打开多个 URL.

                  Thanks for the replies - I modified the suggestions slightly so that I could have more than one URL opened via the function.

                  此代码的另一个版本位于 检查在另一个窗口中打开的 URL

                  There is another version of this code at Check for a URL open on another window

                  var g_urlarray = [];
                  
                  Array.prototype.has = function(value) {
                      var i;
                      for (var i in this) {
                          if (i === value) {
                              return true;
                          }
                      }
                      return false;
                  };
                  
                  
                  function launchApplication(l_url, l_windowName)
                  {
                    var l_width = screen.availWidth;
                    var l_height = screen.availHeight;
                    var winRef;
                  
                    var l_params = 'status=1' +
                                   ',resizable=1' +
                                   ',scrollbars=1' +
                                   ',width=' + l_width +
                                   ',height=' + l_height +
                                   ',left=0' +
                           ',top=0';
                    if (g_urlarray.has(l_url)) {
                      winRef = g_urlarray[l_url];
                    }
                    alert(winRef);
                    if (winRef == null || winRef.closed) {
                        winRef = window.open(l_url, l_windowName, l_params);
                        winRef.moveTo(0,0);
                        winRef.resizeTo(l_width, l_height);
                        g_urlarray[l_url] = winRef;
                    }
                  }
                  

                  推荐答案

                  我会这样做 - 基本上将所有引用的打开窗口存储在函数本身上.当函数触发时,检查窗口是否不存在或已关闭 - 如果是这样,启动弹出窗口.否则,请关注该请求的现有弹出窗口.

                  I'd do it like this - basically store all the referenced opened windows on the function itself. When the function fires, check if the window doesn't exist or has been close - of so, launch the popup. Otherwise, focus on the existing popup window for that request.

                  function launchApplication(l_url, l_windowName)
                  {
                    if ( typeof launchApplication.winRefs == 'undefined' )
                    {
                      launchApplication.winRefs = {};
                    }
                    if ( typeof launchApplication.winRefs[l_windowName] == 'undefined' || launchApplication.winRefs[l_windowName].closed )
                    {
                      var l_width = screen.availWidth;
                      var l_height = screen.availHeight;
                  
                      var l_params = 'status=1' +
                                     ',resizable=1' +
                                     ',scrollbars=1' +
                                     ',width=' + l_width +
                                     ',height=' + l_height +
                                     ',left=0' +
                                     ',top=0';
                  
                      launchApplication.winRefs[l_windowName] = window.open(l_url, l_windowName, l_params);
                      launchApplication.winRefs[l_windowName].moveTo(0,0);
                      launchApplication.winRefs[l_windowName].resizeTo(l_width, l_height);
                    } else {
                      launchApplication.winRefs[l_windowName].focus()
                    }
                  }
                  

                  这篇关于JavaScript window.open 仅当窗口不存在时才打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Fetch multiple links inside foreach loop(在 foreach 循环中获取多个链接)
                  Backbone Fetch Request is OPTIONS method(Backbone Fetch Request 是 OPTIONS 方法)
                  Fetch API leaks memory in Chrome(Fetch API 在 Chrome 中泄漏内存)
                  How can I download and save a file using the Fetch API? (Node.js)(如何使用 Fetch API 下载和保存文件?(Node.js))
                  Send blob data to node using fetch, multer, express(使用 fetch、multer、express 将 blob 数据发送到节点)
                  Sending a custom User-Agent string along with my headers (fetch)(发送自定义用户代理字符串以及我的标头(获取))

                    <tbody id='95syO'></tbody>

                      <legend id='95syO'><style id='95syO'><dir id='95syO'><q id='95syO'></q></dir></style></legend>

                      1. <tfoot id='95syO'></tfoot>

                          <i id='95syO'><tr id='95syO'><dt id='95syO'><q id='95syO'><span id='95syO'><b id='95syO'><form id='95syO'><ins id='95syO'></ins><ul id='95syO'></ul><sub id='95syO'></sub></form><legend id='95syO'></legend><bdo id='95syO'><pre id='95syO'><center id='95syO'></center></pre></bdo></b><th id='95syO'></th></span></q></dt></tr></i><div id='95syO'><tfoot id='95syO'></tfoot><dl id='95syO'><fieldset id='95syO'></fieldset></dl></div>
                        • <small id='95syO'></small><noframes id='95syO'>

                            <bdo id='95syO'></bdo><ul id='95syO'></ul>