如何用JavaScript从另一个页面重定向到一个页面?
window.location.replace('http://sidanmor.com');
这比使用window.location.href = 'http://sidanmor.com'
要**好。
使用replace()
更好,因为它不会在会话历史中保留原网页,这意味着用户不会陷入无休止的后退按钮惨剧。
gt.()
是比较好的,因为它不会保留原网页的会话历史记录,这意味着用户不会陷入无休止的后退按钮惨剧中。
如果你想模拟某人点击一个链接,使用
**window.location.href
*
window.location.href
**。
>.如果你想模拟HTTP重定向,使用
window.location.replace
**。 如果你想模拟HTTP重定向,使用window.location.replace
。
例如:。
// similar behavior as an HTTP redirect
window.location.replace("http://sidanmor.com");
// similar behavior as clicking on a link
window.location.href = "http://sidanmor.com";
摘自此处: [如何用jQuery重定向到另一个页面?][1] 。
[1]: https://stackoverflow.com/questions/503093/how-to-redirect-to-another-page-in-jquery
location.replace
。例如:{{{8243945}}。
// Similar behavior as an HTTP redirect
window.location.replace("http://stackoverflow.com");
// Similar behavior as clicking on a link
window.location.href = "http://stackoverflow.com";