我如何将用户从一个页面转向另一个页面,使用jQuery或纯粹的JavaScript?
当前回答
在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/")
其他回答
我已经使用JavaScript的重定向功能(),它工作了。
<script type="text/javascript">
$(function () {
//It's similar to HTTP redirect
window.location.replace("http://www.Technomark.in");
//It's similar to clicking on a link
window.location.href = "Http://www.Technomark.in";
})
</script>
试试这:
location.assign("http://www.google.com");
编码的例子。
您可以写下按钮点击事件的 URL.Action 在脚本部分如下。
function onclick() {
location.href = '@Url.Action("Index", "Home")';
}
在 PHP、HTML 或 jQuery 部分后写下下面的代码,如果在 PHP 或 HTML 部分中间,则使用 <script> 标签。
location.href = "http://google.com"
<script type="text/javascript">
if(window.location.href === "http://stackoverflow.com") {
window.location.replace("https://www.google.co.in/");
}
</script>