使用jQuery或纯 JavaScript 如何将用户从一页转到另一页?
当前回答
简在JavaScript 贾斯克里普特,您可以通过下列方式将方向转向特定页面:
window.location.replace("http://www.test.com");
或
location.replace("http://www.test.com");
或
window.location.href = "http://www.test.com";
使用 j 查询 :
$(window).attr("location","http://www.test.com");
其他回答
与 jQuery 合作 :
$(window).attr("location", "http://google.fr");
您可以在脚本部分的按钮点击事件下写入 Url. 动作 。
function onclick() {
location.href = '@Url.Action("Index", "Home")';
}
在 JavaScript 和 jQuery 中, 我们可以使用以下代码将一页改到另一页 :
window.location.href="http://google.com";
window.location.replace("page1.html");
以下是一个时间延迟重定向。 您可以将延迟时间设定为任何您想要的时间 :
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Your Document Title</title>
<script type="text/javascript">
function delayer(delay) {
onLoad = setTimeout('window.location.href = "http://www.google.com/"', delay);
}
</script>
</head>
<body>
<script>
delayer(8000)
</script>
<div>You will be redirected in 8 seconds!</div>
</body>
</html>