Share on Google+Share on Google+

JavaScript method location

This page discusses - JavaScript method location

JavaScript method location


In this section, you will learn the use of JavaScript location.href.

JavaScript provides several ways to display any other page in the current browser window using location property of the window object. One of them is location.href which redirects the user straightforward to the specified URL. In the given example, we have specified an URL "" to redirect the user to it.

Here is the code:

<h2>Use of property location.href</h2>
<script language="JavaScript" type = "text/javascript">
function setLocation(){
location.href = "";;
<button onclick="return setLocation();">Go To</button>

Output will be displayed as:

On clicking the you will move to

Download Source code:




Posted on: April 18, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: JavaScript method location  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image