我如何将用户从一个页面转向另一个页面,使用jQuery或纯粹的JavaScript?


当前回答

如何从客户端侧进行重定向:

<!DOCTYPE html> <html> <head> <title>JavaScript and jQuery example to redirect a page or URL </title> </head> <body> <div id="redirect"> <h2>Redirect to another page</h2> </div> <script src="scripts/jquery-1.6.2.min.js"></script> <script> // JavaScript code to redirect a URL window.location.r

其他回答

在我的工作经验中,JavaScript更好地重定向。

它取决于您想要如何更改位置. 如果您想在用户历史中登录您的网站,请使用 window.location.href='ur website';. 否则,如果您不登录历史,请使用 window.location.replace(“您的网站”);。

它适用于每个浏览器:

window.location.href = 'your_url';

警告:这个答案只是作为一个可能的解决方案提供;它显然不是最好的解决方案,因为它需要jQuery。

$(location).prop('href', 'http://stackoverflow.com')

使用:

function redirect(a) {
    location = a
}

求主引导他,求主引导他。

没有必要在位置后进行Href,因为它是有意义的。

jQuery 代码重新引导页面或 URL

您甚至可以直接将 URL 转移到 attr() 方法,而不是使用变量。

第二条路

 window.location.href="http://stackoverflow.com";

你也可以编码如下(两者都是内部相同的):

window.location="http://stackoverflow.com";

第三种方式

第四条路

Location.assign() 方法将新文档上传到浏览器窗口中。

window.location.assign("http://stackoverflow.com"); 

第五条路

如 attr() 方法( jQuery 1.6 引入后)

var url = “http://stackoverflow.com”; $(位置)。prop('href', url);