使用jQuery的重定向有点复杂,简单的重定向没有必要使用jQuery,并且window.location.replace(...)模拟HTTP重定向最接近。
它比window.location.href =''更好,因为replace()不保留原始页面中的会话历史记录,用户使用后退按钮不会看到定向前的页面。如果你想要模拟人为点击链接,可使用location.href。如果你想要模拟HTTP重定向,使用location.replace。
例如:
// similar behavior as an HTTP redirect window.location.replace("http://www.bczs.net"); // similar behavior as clicking on a link window.location.href = "http://www.bczs.net"; // use jQuery 不推荐 $(location).attr('href', 'http://www.bczs.net'); // or $(window).attr('location', 'http://www.bczs.net');