3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
用 JavaScript 取得目前網址與其它網址參數簡單語法 資料來源: https://www.wibibi.com/info.php?tid=82 首先透過 JavaScript 取得目前網頁網址的語法是 location.href,以下簡單範例 alert(location.href); EX:馬上就寫個簡單的範例來取得所有網址資訊 假設我們的網址是:http://www.wibibi.com:80/test.html?tid=222#333  alert('location.href: '+location.href); //輸出値為 location.href: http://www.wibibi.com/test.html?tid=222#333  alert('location.protocol: '+location.protocol); //輸出値為 location.protocol: http:  alert('location.hostname: '+location.hostname); //輸出値為 location.hostname: www.wibibi.com  alert('location.host: '+location.host); //輸出値為 location.host: www.wibibi.com  alert('location.port: '+location.port); //輸出値為 80  alert('location.pathname: '+location.pathname); //輸出値為 location.pathname: /test.html  alert('location.search: '+location.search); //輸出値為 location.search: ?tid=222  alert('location.hash: '+location.hash); //輸出値為 location.hash: #333

本文由jashliaoeuwordpress提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦