什么是自动重定向有人另一个网页的最佳方式? [英] What's the best way to automatically redirect someone to another webpage?
本文介绍了什么是自动重定向有人另一个网页的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从来没有学JavaScript的,但我想这是一个相当简单的问题。只是想知道哪种方法最建议的这些日子。
解决方案
//利用这一点避免重定向时在其浏览器用户点击后退
window.location.replace('http://somewhereelse.com');//使用这个重定向,后退按钮调用将再次触发重定向
window.location.href =http://somewhereelse.com;//给出完整性,基本上是一个别名window.location.href
window.location的=http://somewhereelse.com;
修改:貌似谁张贴更好的答案已经离开,所以用户,我在这里巩固了自己的答案
I've never learnt JavaScript, but I imagine this is quite a simple problem. Just wanted to know which method is most advised these days.
解决方案
// use this to avoid redirects when a user clicks "back" in their browser
window.location.replace('http://somewhereelse.com');
// use this to redirect, a back button call will trigger the redirection again
window.location.href = "http://somewhereelse.com";
// given for completeness, essentially an alias to window.location.href
window.location = "http://somewhereelse.com";
edit: looks like the user who posted the better answer has left SO, i've consolidated his answers here.
这篇关于什么是自动重定向有人另一个网页的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文