location address bar object
Location address bar object
href: Get the complete address in the address bar. JS webpage jump can be realized. location.href = “http://www.sina.com.cn”;
hostname: host name
pathname: file path and filename
#search: query string.
protocol: protocol, such as: http://, ftp://
hash: anchor name. For example: #top
#reload([true]): Refresh the web page. The true parameter indicates forced refresh
Note: After all attributes are reassigned, the web page will automatically refresh.
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script type="text/javascript"> //實(shí)例:測試不同瀏覽器 var str = "<h2>地址欄對象</h2>"; str += "地址欄地址:"+location.href; str += "<br>主機(jī)名:"+location.hostname; str += "<br>文件路徑及文件名:"+location.pathname; str += "<br>協(xié)議:"+location.protocol; document.write(str+"<hr>"); </script> </head> <body > </body> </html>