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

function redirect() {
    location.replace("http://www.ezineasp.net");
}

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

Continue to next tutorial: Javascript Location Redirect Function to learn how to create a redirect URL function in JavaScript.

Recent JavaScript Tutorials

Javascript FSO ShortPath property

Javascript FileSystemObject (FSO) provides a ShortPath property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Path Property

Javascript FileSystemObject (FSO) provides the Path property that can be accessed through the file object or folder object returned by the GetFile or GelFolder method

Javascript FSO Type property

Javascript FileSystemObject (FSO) provides a Type property that can be accessed through file object or folder object returned by the GetFile or GetFolder method

Javascript FSO ShortName property

Javascript FileSystemObject (FSO) provides a ShortName property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Name Property

Javascript FileSystemObject (FSO) provides a Name property that can be accessed using file object or folder object.