使用jQuery或纯 JavaScript 如何将用户从一页转到另一页?
当前回答
以下是一个时间延迟重定向。 您可以将延迟时间设定为任何您想要的时间 :
<!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>
其他回答
您需要在代码中输入这条线 :
$(location).attr("href","http://stackoverflow.com");
如果你没有jQuery, 和JavaScript一起去:
window.location.replace("http://stackoverflow.com");
window.location.href("http://stackoverflow.com");
var url = 'asdf.html';
window.location.href = url;
在 JavaScript 和 jQuery 中, 我们使用以下代码重定向页面 :
window.location.href="http://google.com";
window.location.replace("page1.html");
但您可以在 jQuery 中设定函数, 以重定向页面 :
jQuery.fn.redirect=function(url)
{
window.location.href=url;
}
调用此函数 :
jQuery(window).redirect("http://stackoverflow.com/")
但如果有人想重回主页 他可能会使用下面的片段
window.location = window.location.host
如果你有三种不同的环境,如发展、中转和生产,将会很有帮助。
您可以将这些单词放入铬控制台, 来探索此窗口或窗口。 位置对象 。 @ info: whatsthis火虫控制台
您可以在以下代码中使用它,getRequestToForwardPage
是请求映射( 即请求映射) 。URL URL URL URL 網址)您也可以使用您的 URL。
function savePopUp(){
$.blockUI();
$.ajax({
url:"GuestHouseProcessor?roomType="+$("#roomType").val(),
data: $("#popForm").serialize(),
dataType: "json",
error: (function() {
alert("Server Error");
$.unblockUI();
}),
success: function(map) {
$("#layer1").hide();
$.unblockUI();
window.location = "getRequestToForwardPage";
}
});
这是针对申请的相同背景。
如果您想要只使用 jquery 特定代码, 跟随以下代码可能会有帮助 :
$(location).attr('href',"http://www.google.com");
$jq(window).attr("location","http://www.google.com");
$(location).prop('href',"http://www.google.com");