location網(wǎng)址列對(duì)象
Location網(wǎng)址列物件
#href:取得網(wǎng)址列中完整的位址??梢詫?shí)現(xiàn)JS的網(wǎng)頁(yè)跳轉(zhuǎn)。 location.href = “http://www.sina.com.cn”;
#hostname:主機(jī)名稱(chēng)
- ##pathname:檔案路徑及檔名
- search:查詢(xún)字串。
- protocol:協(xié)議,如:http://、ftp://
- #hash:錨點(diǎn)名稱(chēng)。如:#top
- reload([true]):重新整理網(wǎng)頁(yè)。 true參數(shù)表示強(qiáng)制刷新
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script type="text/javascript"> //實(shí)例:測(cè)試不同瀏覽器 var str = "<h2>地址欄對(duì)象</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>
#