location地址欄對象
Location地址欄對象
href:獲取地址欄中完整的地址。可以實現(xiàn)JS的網(wǎng)頁跳轉(zhuǎn)。location.href = “http://www.sina.com.cn”;
hostname:主機(jī)名
pathname:文件路徑及文件名
search:查詢字符串。
protocol:協(xié)議,如:http://、ftp://
hash:錨點名稱。如:#top
reload([true]):刷新網(wǎng)頁。true參數(shù)表示強制刷新
注意:所有的屬性,重新賦值后,網(wǎng)頁將自動刷新。
<!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>主機(jī)名:"+location.hostname; str += "<br>文件路徑及文件名:"+location.pathname; str += "<br>協(xié)議:"+location.protocol; document.write(str+"<hr>"); </script> </head> <body > </body> </html>
一輛想出軌的無軌電車
代碼少點還行,能看懂
8年前 添加回復(fù) 0