Redirect using JavaScript/jQuery with href and replace. There are multiple ways to redirect users to one page from another page. Among all these methods, some need user interactions and some do auto redirects. Some of the multiple ways are: replace, href, assign, etc.
The most commonly used and efficient ways are replace and href. Because they are mostly supported by every browser. Let’s check them in detail.
If you want to simulate someone clicking on the link, use location.href
If you want to simulate an HTTP redirect, use location.replace
window.location.replace("https://www.codinghelpsolutions.com/"); window.location.href = "https://www.codinghelpsolutions.com/";
Some other ways are:
// window.location window.location.replace('https://www.codinghelpsolutions.com/') window.location.assign('https://www.codinghelpsolutions.com/') window.location.href = 'https://www.codinghelpsolutions.com/' document.location.href = '/path' // window.history window.history.back() window.history.go(-1) // window.navigate; ONLY for old versions of Internet Explorer window.navigate('page.html') // jQuery $(location).attr('href','https://www.codinghelpsolutions.com/') $(window).attr('location','https://www.codinghelpsolutions.com/') $(location).prop('href', 'https://www.codinghelpsolutions.com/')
You can get more details about this topic here.
To get to know more about other JavaScript topics, you can check these articles too.
Please follow and like us: