location object

The location object represents the URL information of the current page. For example, a complete URL:

http://www.example.com:8080/path/index.html?a=1&b=2#TOP

can be obtained using location.href. To get the value of each part of the URL, you can write:

location.protocol; // 'http'
location.host; // 'www.example.com'
location.port; // '8080'
location.pathname; // '/path/index.html'
location.search; // '?a=1&b=2'
location.hash; // 'TOP'

To load a new page, you can call location.assign(). If you want to reload the current page, it is very convenient to call the location.reload() method.

location Object properties:

QQ截图20161012171542.png

location Object methods:

QQ截图20161012171548.png

Continuing Learning
||
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>location</title> </head> <script type="text/javascript"> var myurl=window.location.href; document.write("当前网址:"+myurl); </script> </head> <body> </body>
submitReset Code