javascript 如何在 Jquery 中制作重定向页面?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18265847/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 11:16:25  来源:igfitidea点击:

How Can I Make a Redirect Page in Jquery?

javascriptjqueryhtmlurlredirect

提问by JT Nolan

I want to build a page that displays html for a short while and then redirects the user to another URL without opening a new window. How can this be done quickly in Jquery?

我想构建一个显示 html 一小段时间的页面,然后将用户重定向到另一个 URL,而无需打开新窗口。如何在 Jquery 中快速完成此操作?

回答by Sonny Ng

<script type="text/javascript">
    window.onload = function() {
        setTimeout(function() {
            window.location = "your link";
        }, 5000);
    };
</script>

After 5 second, it will redirect. replace"your link" with the link you want.

5 秒后,它将重定向。用你想要的链接替换“你的链接”。

Hope it helps.

希望能帮助到你。

回答by xdazz

Doesn't need javascript, just add the meta tag in the head:

不需要 javascript,只需在头部添加元标记:

// for 5 seconds
<meta http-equiv="refresh" content="5; url=http://www.example.com/" />

回答by roycable

If you're not wanting to open the URL in a new window use window.location.href = xx

如果您不想在新窗口中打开 URL,请使用 window.location.href = xx

setTimeout(function(){
   window.location.href = 'http://www.google.com';
},5000);// after 5 seconds

回答by Rohan Kumar

Try this,

试试这个,

// you can use jquery document ready function to call your code after DOM ready
$(document).ready(function(){
    setTimeout(function(){
       window.open('your url to open');
    },5000);// after 5 seconds
});

回答by Eswara Reddy

Try this

试试这个

setTimeout(function() {
   window.location = "new url";
}, 5000);