这篇文章主要介绍使用javascript实现页面跳转的案例,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
js页面跳转方法:1、使用“location.href="URL"”;2、使用“location.replace("URL")”;3、使用“location.assign("URL")”;4、使用“window.open("URL")”。
javascript实现页面跳转的方法:
1、使用location.href属性跳转到其他网页
语法:
location.href="URL";
示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<p>这是<i>location.href</i>方式的示例</p>
<button onclick="myFunc()">点击这里</button>
<!--重定向到其他网页的脚本-->
<script>
function myFunc() {
window.location.href="https://www.php.cn";
}
</script>
</body>
</html>
2、使用location.replace()方法跳转到其他网页
语法:
location.replace("URL");
示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<p>这是<i>location.replace()</i>方式的示例</p>
<button onclick="myFunc()">点击这里</button>
<!--重定向到其他网页的脚本-->
<script>
function myFunc() {
location.replace("https://www.php.cn");
}
</script>
</body>
</html>
3、使用location.assign()方法跳转到其他网页
语法:
location.assign("URL")
示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<p>这是<i>location.assign()</i>方式的示例</p>
<button onclick="myFunc()">点击这里</button>
<!--重定向到其他网页的脚本-->
<script>
function myFunc() {
location.assign("https://www.php.cn");
}
</script>
</body>
</html>
4、使用window.open()方法跳转到其他网页
语法:
window.open("URL");
示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<p>这是<i>window.open()</i>方式的示例</p>
<button onclick="myFunc()">点击这里</button>
<!--重定向到其他网页的脚本-->
<script>
function myFunc() {
window.open("https://www.php.cn");
}
</script>
</body>
</html>
以上是“使用javascript实现页面跳转的案例”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注天达云行业资讯频道!