javascript怎么实现页面跳转
时间:2021-04-22 来源:互联网
今天PHP爱好者为您带来js页面跳转方法:1、使用“location.href="URL"”;2、使用“location.replace("URL")”;3、使用“location.assign("URL")”;4、使用“window.open("URL")”。希望对大家有所帮助。
本教程操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。
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怎么实现页面跳转的详细内容,更多请关注php爱好者其它相关文章!
-
杖剑传说职业技能有哪些-全职业特色技能解析 2025-06-25
-
情侣吵架:因为“多喝热水”引发的血案。 2025-06-25
-
ATOM币空投平台和交易所支持情况 2025-06-25
-
世界之外如星璀璨世界之间活动规则 2025-06-25
-
新三国志曹操传有哪些礼包-游戏礼包兑换码大全 2025-06-25
-
纸嫁衣8千子树什么时候上线-最新公测时间公布 2025-06-25