Thursday, July 5, 2018

How do I redirect to another web page using javascript ?


How do I redirect to another web page using javascript ?



There is three methods to redirect user to other web page using java-script.


  • window.location.href
  • window.location.replace
  • window.location.assign

window.location.href method is used to get location of current web-page. Also using this method we can redirect browser to another page.
Example:  window.location.href="http://techpowerinfo.blogspot.com/";


window.location.replace method removes the URL of current web page from the history. So, it is impossible to  go back to the previous (or original) web-page.
Example:  window.location.replace("http://techpowerinfo.blogspot.com/");


window.location.assign  method adds the URL of new web page to the history stack. So, it is possible to move back and forth , and redirects to new web page.
Example:  window.location.assign("http://techpowerinfo.blogspot.com/");

No comments:

Post a Comment