Jquery页面跳转 JavaScript 页面跳转 跳转路径错误问题
转载子:极客导航 - Jquery页面跳转 JavaScript 页面跳转 跳转路径错误问题
1.使用Jquery实现跳转
$(location).attr('href',"http://www.google.com"); $jq(window).attr("location","http://www.google.com"); $(location).prop('href',"http://www.google.com");
2.使用JavaScript实现跳转
// 相当于 HTTP redirect window.location.replace("http://stackoverflow.com"); // 相当于 clicking on a link window.location.href = "http://stackoverflow.com";
JavaScript其它的可实现页面跳转的方式
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);
3.页面跳转路径错误问题
ie8以下的页面跳转需要使用绝对路径,使用相对路径的时候ie会自动网跳转的Url上面加上当前页面的路径,这会导致跳转错误。 下面是解决办法:
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; } }
相关推荐
hhanbj 2020-11-17
81427005 2020-11-11
EdwardSiCong 2020-11-23
85477104 2020-11-17
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
84483065 2020-09-11
momode 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
82550495 2020-08-03
tthappyer 2020-08-03
84901334 2020-07-28
tthappyer 2020-07-25
TONIYH 2020-07-22
tztzyzyz 2020-07-20
83510998 2020-07-18
81463166 2020-07-17