JavaScript Webpage Redirection

Webpage redirection is a JavaScript technique through which you can easily move from one webpage to another webpage. Suppose you have a webpage and you want to redirect all the users who open this webpage to another webpage so for it you can use JavaScript's redirection technique. You can do webpage redirection through various ways. One way of redirection, you can use window object's location property to redirect webpage. Example is mentioned below: Code


<html>
  <head>
    <title>Webpage Redirection Example</title>
  </head>

  <body>
    <input type='button' name='myButton' value='Redirect to Google' 
    id='myButton' onclick='window.location="www.google.com"'>
  </body>
</html>
In above mentioned example we have written a JavaScript statement on onClick event of 'Redirect to Google'. window.location required a URL of a webpage on which you want to redirect, In above present example we gave 'www.google.com' URL for redirection. You can change it as whatever you want. You can use JavaScript's document object's URL property to redirect webpage. Example is mentioned below:

Code

<html>
  <head>
    <title>Webpage Redirection Example</title>
  </head>
  
  <body>
    <input type='button' name='myButton' value='Redirect to Google' 
    id='myButton' onclick='document.url="www.google.com"'>
  </body>
</html>
In above mentioned example we have written a JavaScript statement on onClick event of 'Redirect to Google'. document.url required a URL of a webpage on which you want to redirect, In above present example we gave 'www.google.com' URL for redirection. You can change it as whatever you want.