Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

How can I redirect the user from one page to another using jQuery or pure JavaScript?

1 Answer

0 votes
by (106k points)

For redirecting to another page there is no need for jQuery and you can use window.location.replace()in the argument you need to pass the URL of the page where you want to redirect and it will do the work.

There are two things the first is if you want someone to redirect just by clicking on a link, then location.href is preferable.

But in case of  HTTP redirect, you can use location.replace.

An example code that shows the use of both the methods:-

function redirect (url) {

var ua = navigator.userAgent.toLowerCase(),

isIE = ua.indexOf('msie') !== -1,

version = parseInt(ua.substr(4, 2), 10); 

if (isIE && version < 9) {

var link = document.createElement('a'); 

link.href = url; 

document.body.appendChild(link); 

link.click(); 

else { 

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

window.location.replace("http://intellipaat.com");  

   } 

}

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...