无需焦点打开新选项卡无法在Chrome浏览器中使用

时间:2015-03-31 09:36:13

标签: javascript jquery google-chrome

此代码工作较早。但现在几天它不起作用了。可能是由于Chrome新版本。请给我一些工作代码。

<html>
  <head>
   <script src="http://code.jquery.com/jquery-2.1.0.min.js" type="text/javascript"></script>
   <script type="text/javascript">

$(document).ready(function(e) {
    $("#test").click(function(e) {
        var a = document.createElement("a");
        a.href = "http://www.google.com/";
        var evt = document.createEvent("MouseEvents");
        //the tenth parameter of initMouseEvent sets ctrl key
        evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, false, 0, null);
        a.dispatchEvent(evt);   
    });

}); 
   </script>
  </head>
  <body>
        Google
        <a id="test" href="http://www.stupidcodes.com" target="_blank" >Open Google</a>
  </body>
</html>

0 个答案:

没有答案
相关问题