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; }
}

转载于:https://www.cnblogs.com/aftereclipse/p/4629541.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值