location object in JavaScript

Location object we can use to reload the page and browse to a new page. We can get the complete or part of the URL of current page by using location object.

Let us start with some simple uses.
Location ObjectDescription
reloadRefreshing the current page
HostnameGetting the hostname of current URL
hrefFull URL of current page

assign

We can use assign method to add a new URL to our browser so we can send to a new page.

You can use Back button of your browser to return to this page.

Source code is here
<input type=button value='JavaScirpt Home' onClick=window.location.assign('site_map.php');>
Demo button is here
Use Back button to return to this page.

replace

Replace method will also take you to a new URL but you can't use Back button of your browser to return to this page. Unlike assign method replace method delete history or previous URL from browser.

Source code is here.
<input type=button value='New Page' onClick=window.location.replace('location-demo.php');>
Demo button is here.
Use the link on the New Page to return to this page as you can't use Back button.

Subscribe to our mailing list

* indicates required
Subscribe to plus2net
Your Rating


Google+

Post Comment This is for short comments only. Use the forum for more discussions.




Subscribe to our mailing list

* indicates required
Subscribe to plus2net
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2017 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer