Javascript Window Location Href URL

by top54u.com 04 Jul, 2008
Spotlight.....

Javascript location href property of DOM window object allows you to get or set the current URL. You can access the href property through location.href or window.location.href. Both methods will return the same result. If you are trying to assign the value retrieved from the Javascript location href to a variable or alert message box then it will return the current URL of the browser. And if you are trying to assign the value to the Javascript location href property then it will redirect the current URL to the specified location URL.

 

Syntax for Javascript Window Location Href URL

 

window.location.href = "URL";

or use directly

location.href = "URL";

 

Examples of Javascript Window Location Href URL

 

Example 1: Get the current URL

<script language="javascript" type="text/javascript">

 

document.write(window.location.href);

 

</script>

 

OR

 

<script language="javascript" type="text/javascript">

 

document.write(location.href);

 

</script>

 

 

Example 2: Set the new Location Href URL

 

<script language="javascript" type="text/javascript">

 

window.location.href = "http://programming.top54u.com";

 

</script>

OR

 

<script language="javascript" type="text/javascript">

 

window.location.href = "http://programming.top54u.com";

 

</script>

You can also create the Javascript function to set the location href property by using onclick event of input type field or any other event that is supported by all the commonly used web browsers.

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

8/23/2008 8:47:10 PM

OUR SPONSORS[+ advertise here]
related videos.....
recent posts.....
top54u ezines.....