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-11-19 -
Linux中软连接和硬链接的区别、优缺点和应用场景等 时间:2025-11-19 -
什么是Hypervisor Hypervisor虚拟机监控程序详解 时间:2025-11-19 -
numeric是什么数据类型 decimal和numeric的区别 时间:2025-11-19 -
Java中public class和class的区别 时间:2025-11-19 -
Android中Activity跳转的两种实现方法 时间:2025-11-19
今日更新
-
上单行为是什么梗梗姐姐 揭秘游戏圈爆笑名场面真相
阅读:18
-
yy歪歪漫画官方主入口-yy漫画最新首页地址
阅读:18
-
币安风控Meme币交易原因解析及应对策略
阅读:18
-
yy漫画首页入口-热门章节一键畅读
阅读:18
-
超星网络学生登录入口 超星学生通官网网页版快速登录
阅读:18
-
币安风控申诉被拒的5大关键原因及解决方案
阅读:18
-
揭秘上等马梗出处:职场人秒懂的暗号文化,3秒get社畜生存法则
阅读:18
-
《龙骑士学园》官方入口地址
阅读:18
-
126邮箱登录入口-126邮箱网页版快速登录
阅读:18
-
币安风控机制是否受交易量阈值影响解析
阅读:18










