080_获取当前页面地址
生活随笔
收集整理的這篇文章主要介紹了
080_获取当前页面地址
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1. window.location對象可用于獲取當前頁面地址(URL)并把瀏覽器重定向到新頁面。
2. window.location.href屬性返回當前頁面的URL。
3. window.location.hostname屬性返回(當前頁面的)因特網主機的名稱。
4. window.location.pathname屬性返回當前頁面的路徑名。
5. window.location.protocol屬性返回頁面的web協議(http:或https:)。
6. window.location.port屬性返回(當前頁面的)互聯網主機端口的編號。
7. 例子
7.1. 新建一個Web項目
7.2. 編寫Location.html
<!DOCTYPE html> <html lang="zh-CN"><head><meta charset="utf-8" /><title>獲取當前頁面地址</title></head><body><script type="text/javascript">document.write('頁面位置是: ' + window.location.href + '<br />');document.write('頁面主機名是: ' + window.location.hostname + '<br />');document.write('頁面路徑是: ' + window.location.pathname + '<br />');document.write('頁面協議是: ' + window.location.protocol + '<br />');document.write('端口號是: ' + window.location.port + '<br />');</script></body> </html>7.3. 效果圖
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的080_获取当前页面地址的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 079_用户屏幕的信息
- 下一篇: 081_浏览器历史