如何使用 window.location 来重定向到一个不同的 URL?
你可能遇到过以下情况:你点击一个 URL,打开页面 X,但实际上却被定向到了另一个页面 Y。这是由于页面重定向造成的。
使用 JavaScript 在客户端进行页面重定向非常简单。要将网站访问者重定向到一个新页面,你只需在 head 部分中添加一行,如下所示。

示例
你可以尝试运行以下代码,了解如何使用 window.location 来重定向一个 HTML 页面。这里,我们将重定向到主页
<html>
<head>
<script>
<!--
function Redirect() {
window.location.assign("https://tutorialspoint.com");
}
//-->
</script>
</head>
<body>
<p>Click the following button, you will be redirected to home page.</p>
<input type="button" value="Redirect Me" onclick="Redirect();" />
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP