js如何打开新页面

2022年6月29日 22点热度 0人点赞

JS实现打开新页面的方法有多种,下面我们看来下有哪些?

方法/步骤

  • 第一种:在当前页面打开新页面,具体代码如下(经过测试可用)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <title>JS实现打开新页面</title>

    <script type="text/javascript">

    function open1(){

    window.location.href="http://www.baidu.com";

    }

    </script>

    </head>

    <body>

    <a href="javascript:void(0)" onclick="open1()">点击我,在当前页面打开指定的页面</a>

    </body>

  • 第二种:在新窗口中打开指定的页面,具体代码如下(经过测试可用)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <title>JS实现打开新页面</title>

    <script type="text/javascript">

    function open1(){

    window.location.href="http://www.baidu.com";

    }

    </script>

    <script type="text/javascript">

    function open2(){

    window.open("http://www.baidu.com");

    }

    </script>

    </head>

    <body>

    <a href="javascript:void(0)" onclick="open1()">点击我,在当前页面打开指定的页面</a>

    </br></br></br>

    <a href="javascript:void(0)" onclick="open2()">点击我,会在新窗口中打开指定的页面</a>

    </body>

    END
经验内容仅供参考,如果您需解决具体问题(尤其法律、医学等领域),建议您详细咨询相关领域专业人士。
作者声明:本篇经验系本人依照真实经历原创,未经许可,谢绝转载。
展开阅读全部

laozhao

这个人很懒,什么都没留下

文章评论