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>
posted @ 2012-07-30 13:50  WebApi  阅读(1401)  评论(0编辑  收藏  举报
CopyRight © 博客园 WebAPI