$(location).attr('href',"http://www.google.com"); $jq(window).attr("location","http://www.google.com"); $(location).prop('href',"http://www.google.com");
// 至關於 HTTP redirect window.location.replace("http://stackoverflow.com"); // 至關於 clicking on a link window.location.href = "http://stackoverflow.com";
window.history.back(-1); // back window.navigate("top.jsp"); // old-IE-only self.location="top.htm"; top.location="error.jsp"; window.location = window.location.host; window.location.assign("http://www.mozilla.org"); document.location.href = '/path'; window.history.go(-1);
ie8如下的頁面跳轉須要使用絕對路徑,使用相對路徑的時候ie會自動網跳轉的Url上面加上當前頁面的路徑,這會致使跳轉錯誤。 下面是解決辦法:javascript
function Redirect (url) { var ua = navigator.userAgent.toLowerCase(), isIE = ua.indexOf('msie') !== -1, version = parseInt(ua.substr(4, 2), 10); // Internet Explorer 8 and lower if (isIE && version < 9) { var link = document.createElement('a'); link.href = url; document.body.appendChild(link); link.click(); } // All other browsers else { window.location.href = url; } }