How do I use a header location in jQuery?
This question already has an answer here:
Headers are interpreted prior to the rendering of the document, and before jQuery is even loaded so these aren't an option. Instead, you can redirect the browser using document.location
.
document.location.href = 'www.google.co.in';
For a jQuery approach you can use
$(location).attr('href', 'www.google.co.in');
however I would favor the plain javascript version.
You can use:
window.location.assign('www.google.co.in');
or
window.location.href = 'www.google.co.in';
or
window.location.replace('www.google.co.in');
The difference is that assign()
will just cause a new document to load. While replace()
will replace the current document and replace the current history with that URL making it so you can't go back to the previous document loaded.
Use
window.location.href="www.google.co.in";
for redirection.
and
window.location.reload(true);
to reload the page
链接地址: http://www.djcxy.com/p/1950.html上一篇: URL重定向Javascript
下一篇: 我如何在jQuery中使用标题位置?