best way to redirect user using jquery-javscript?


I have seen many methods like window.location.href=url, window.location.replace(...) and window.location, but can anyone tell me which is the best method to redirect user from one webpage to another using jQuery or javascript?

thank you


Asked by:- jaya
2
: 2534 At:- 6/14/2017 10:49:31 AM
jQuery javascript window.location redirect







2 Answers
profileImage Answered by:- vikas_jk

window.location.replace(url) is better than using window.location.href

.replace() does not keep the originating page in the session history, meaning the user won't get stuck in a never-ending back-button fiasco, as it simulates an HTTP redirect

while windows.location.href provides similar behavior as clicking on a link.

2
At:- 6/14/2017 3:41:50 PM Updated at:- 12/9/2022 7:35:27 AM
thank you for you explanation 0
By : jaya - at :- 6/15/2017 7:32:44 AM


profileImage Answered by:- Vinnu

If you want to simulate someone clicking on a link, use location.href.

If you want to simulate an HTTP redirect, use location.replace.

// similar behavior as an HTTP redirect
window.location.replace("http://example.com");

// similar behavior as clicking on a link
window.location.href = "http://example.com";

Thanks

0
At:- 12/9/2022 4:05:18 PM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use