如何使用 JavaScript 进行重定向?

如何使用 JavaScript 从另一个页面重定向到页面?

答案

window.location = "http://www.yoururl.com";
window.location.replace('http://sidanmor.com');
// 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";
document.location = "MyPage.php?action=DoThis";
// 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";
window.location = url;

window.location="url";相比window.location="url";只执行location="url";会容易得多location="url";我总是用那个