location地址栏对象

Location地址栏对象

  • href:获取地址栏中完整的地址。可以实现JS的网页跳转。location.href = “http://www.sina.com.cn”;

  • hostname:主机名

  • pathname:文件路径及文件名

  • search:查询字符串。

  • protocol:协议,如:http://、ftp://

  • hash:锚点名称。如:#top

  • reload([true]):刷新网页。true参数表示强制刷新

注意:所有的属性,重新赋值后,网页将自动刷新。

<!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>


继续学习
||
<!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>
提交重置代码
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!