首页 > 编程开发 > HTML/html5    日期:2023-07-31 / 浏览

html页面点击按钮实现页面跳转

方法1、在button标签外嵌套一个a标签,利用超链接进行跳转;

<a href="https://www.baidu.com/" target="_blank">
 <button>进入baidu首页</button>
</a>

方法2、在button标签中添加οnclick="window.location.href=‘页面url’"代码,使用onclick事件进行跳转。

<button onclick="window.location.href = 'https://www.baidu.com/' target="_blank"">进入baidu首页</button>

html页面自动跳转方法

1.使用meta元素

<meta http-equiv="refresh" content="5;url=hello.html">

http-equiv=“refresh” 是刷新页面,5秒后执行刷新操作,url是跳转的目的页面地址。

<meta http-equiv="refresh" content="5">

这行代码的意思是只刷新,不跳转。

2.使用script代码

立即跳转到hello.html页面。

<script type="text/javascript">
    window.location.href = 'hello.html';
</script>

或者

<script language="javascript">
    location.replace("http://www.baidu.com/");
</script>

5秒后跳转到hello.html页面。

<script type="text/javascript">
    setTimeout("window.location.href = 'hello.html'", 5000);
</script>

3.判断是否手机端

<script type="text/javascript">
var wapurl = window.location.pathname; 
if
    (/Android|webOS|iPhone|iPod|BlackBerry|Windows CE|Windows Phone/i.test(navigator.userAgent))
{if
    (window.location.href.toLowerCase().indexOf("?pc")<0)
{try
    {window.location.href="/wap"+wapurl}
    catch(e){}}
    }
</script>

觉得上面的内容有用吗?快来点个赞吧!

点赞() 我要打赏

温馨提示 : 本站内容来自会员投稿以及互联网,所有源码及教程均为作者总结编辑,请大家在使用过程中提前做好备份,以免发生无法预知的错误,源码类教程请勿直接用于生产环境!

 可能感兴趣的文章

1 2 3 4 5