函数Window.focus在IE中不起作用(8,9,10,11) [英] function Window.focus doesn't work in IE (8, 9, 10, 11)

查看:967
本文介绍了函数Window.focus在IE中不起作用(8,9,10,11)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,这个代码打开新标签并专注于它。

Here is my code, and this code to open new tab and focus on it.


  • 如果标签尚未打开,我将使用指定名称打开它。

  • 如果打开选项卡,我将通过使用window.focus();

快速测试: http://jsfiddle.net/u2jd2oLw/1/

Javascript代码

Javascript Code

var tabs = [];
$('#btnOpenTab').on('click', function(){
    openTab('http://google.com.vn', 'GG');
});


function openTab(url, tabNm) {
    try {
        if (tabs[tabNm]) {
            tabs[tabNm].focus();
        } else {
            var mTab = window.open(url, tabNm);
            tabs[tabNm] = mTab;
            tabs[tabNm].focus();
        }
    } catch(e) {
        alert(e.message);
    }
}

HTML代码

<button id="btnOpenTab">Open Tab</button>

实际上,我在IE11检查时发现访问被拒绝

Actually, I check in IE11, it occurred that "Access is denied"

我试图通过取消选中CheckBox来关闭选项:打开弹出窗口阻止程序。

And I tried to turn off option: "Turn on Pop-up Blocker" by un-check CheckBox.

你有什么建议吗?

谢谢!!

推荐答案

由于安全问题,这将有效一次

This will work once due to the security issues

$(function() {
  $('#btnOpenTab').on('click', function(){
    openTab('http://google.com.vn', 'GG');
  });
});

function openTab(url, tabNm) {
  var mTab = window.open("", tabNm);
  mTab.document.write('<body onload="window.focus(); location.replace(\''+url+'\')">Please wait...</body>');
  mTab.document.close();
}

它无法运行两次,因为一旦页面加载它就不再是同源。

It failed to run twice because once the page loads it is no longer same origin.

我尝试使用iFrame,但Google现在也阻止了

I tried with an iFrame, but Google blocks that too now

这篇关于函数Window.focus在IE中不起作用(8,9,10,11)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆