欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jq页面跳转到新页面(js点击跳转到指定页面)

程序员文章站 2023-11-29 10:42:46
1.使用jquery实现跳转$(location).attr('href',"http://www.google.com");$jq(window).attr("location","http://w...

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://*.com");
// 相当于 clicking on a link
window.location.href = "http://*.com";

javascript其它的可实现页面跳转的方式

window.history.back(-1);
window.navigate("top.jsp"); //old-ie-only
self.location = 'top.jsp';
top.location = 'top.jsp';
window.location=window.locaiton.host;
winodw.locaiton.assign('http://www.baidu.com');
ducument.location.href='/path';
window.history.go(-1);

3.页面跳转路径错误问题

ie8以下的页面跳转需要使用绝对路径,使用相对路径的时候ie会自动网跳转的url上面加上当前页面的路径,这会导致跳转错误。 下面是解决办法:

function redirect (url) { 
 var ua = navigator.useragent.tolowercase(),