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學習者快速成長!