Javascript Window Location Replace Function

by top54u.com on 08 Jul, 2008
   
   
Spotlight.....

Javascript location replace function of DOM window object provides the functionality to replace the current URL with new location URL and also allows you to redirect the current URL. You can call the Javascript location replace function using any event of form input fields such as input type button onclick event to replace the current URL with new URL. You can also code the location replace function in the Javascript block of the HTML <head> head section to call the location replace function on body load automatically to redirect the current URL to new URL. Any of the location.replace or window.location.replace can be used in the Javascript code.

 

Syntax of Javascript Window Location Replace Function

 

location.replace("URL");

 

or

 

window.location.replace("URL");

 

Javascript location replace function accepts 1 parameter of string value type as new location URL path.

 

Example of Javascript Window Location Replace Function

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head>

<title>Javascript window location replace</title>

 

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

 

function redirect()

{

 

location.replace("http://programming.top54u.com");

 

}

 

</script>

 

</head>

<body>

<input type="button" value="Location Replace URL" onclick="redirect();" />

</body>

</html>

Above example code for Javascript window location replace function will redirect to new URL onclick event of input type button of HTML document.

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
Loading



Spotlight...
related videos.....
recent posts.....
top54u ezines.....
product spotlight.....