js打开新页面,非window.open()
js打开新页面,非window.open()
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>无标题页</title> </head> <body> <div> <div onclick="openpage('http://www.baidu.com')">测试dom</div> </div> </body> </html> <script type="text/javascript"> function openpage(url) { var link; if(document.getElementById("opennewpagelink")==null) { var _link=document.createElement("a"); link=document.body.appendChild(_link); link.id="opennewpagelink"; link.setAttribute("target", "_blank"); }else{ link=document.getElementById("opennewpagelink"); } link.setAttribute("href", url); if(link.click) { link.click(); }else{ window.open(url); } } </script>
//成功一定有方法,失败一定有原因。