Window.open在第二次或更多次点击时没有关注IE

时间:2016-12-23 15:22:07

标签: javascript file internet-explorer

我正在使用window.open打开我的PDF文件。以下是我的代码。

各种浏览器的反应:

  1. 在chrome中:首次单击PDF图标时,在新窗口中打开PDF文件。我没有关闭打开的PDF。每次当我再次单击相同的PDF图标时,它会再次聚焦同一文件
  2. 在firefox中:第一次点击时,新窗口打开PDF文件(几乎与chrome相同),但是在不关闭现有PDF的情况下随后点击同一文件,它会一次又一次地打开同一个文件并将其聚焦
  3. 在IE中:这是主要问题。在第一次点击时,与其他浏览器一样,但在随后的点击中,打开的文件没有得到集中,根本没有任何事情发生。 反正有没有让IE专注于在新窗口中打开的相同PDF上进行后续点击? 无论如何还要让firefox一次又一次地停止打开同一个文件,只关注Chrome中的现有文件吗?
  4. 代码示例:
  5. function open_page(url, name, features) {
        var win = window.open(url,
                             (name == null ? 'page' : 'test'),
                             (features == null ? 'menubar=1,toolbar=1,scrollbars=1,width=1024,height=768,resizable=1' : features));
    
        win.focus();
    
        if (win == null) {
            alert('Not open');
        } else {
            document.isUnloading = false;
            console.log("#2");
        }
    }
    

    试过以下内容,但仍然没有在IE中工作。我将tge文档集中在第3次点击,第5次和第7次等等。不确定为什么它只能用于替代点击。

      function open_page(url, name, features) {
            alert("1"+win);
            if (win == null) {
                console.log("#1");
                win = open(url, (name == null ? 'page' : 'test'), (features == null ? 'menubar=1,toolbar=yes,scrollbars=yes,top=500,left=500,width=1024,height=768,resizable=yes' : features));
            }
            else if (isIE()) {
                console.log("#2");
                win.close();
                alert(win);
                win = open(url, (name == null ? 'page' : 'test'), (features == null ? 'menubar=1,toolbar=yes,scrollbars=yes, top=500,left=500,width=1024,height=768,resizable=yes' : features));
    
            }
            else {
                console.log("#3");
                window.location.href = url;
                win.focus();
            }
    

0 个答案:

没有答案