js实现在新标签页打开页面

这种方法打开新标签页要在IE9+以上浏览器才可以!

    <html>  
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8">  
        <title>Title</title>  
        <script src="jquery.js"></script>  
        <script type="text/javascript">  
        $(function() {  
            $("#btn").click(function() {  
                //var a = $('a')[0];  
                var a = $("<a href='http://www.baidu.com' target='_blank'>百度</a>").get(0);    
                var e = document.createEvent('MouseEvents');  
                e.initEvent('click', true, true);  
                a.dispatchEvent(e);  
                console.log('event has been changed');  
            });  
        });    
        </script>  
    </head>    
    <body>  
        <input type="button" value="百度" id="btn">  
    </body>  
    </html>

 

posted @ 2014-09-03 11:31  史洲宇  阅读(8115)  评论(0编辑  收藏  举报