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">
            //实例:测试不同浏览器
            var str = "<h2>地址栏对象</h2>";
            str += "地址栏地址:"+location.href;
            str += "<br>主机名:"+location.hostname;
            str += "<br>文件路径及文件名:"+location.pathname;
            str += "<br>协议:"+location.protocol;
            document.write(str+"<hr>");
        </script>
    </head>
    <body >
    </body>
</html>


Continuing Learning
||
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script type="text/javascript"> //实例:测试不同浏览器 var str = "<h2>地址栏对象</h2>"; str += "地址栏地址:"+location.href; str += "<br>主机名:"+location.hostname; str += "<br>文件路径及文件名:"+location.pathname; str += "<br>协议:"+location.protocol; document.write(str+"<hr>"); </script> </head> <body > </body> </html>
submitReset Code