萬盛學電腦網

 萬盛學電腦網 >> 腳本專題 >> javascript >> js獲取當前頁面路徑示例講解

js獲取當前頁面路徑示例講解

 本篇文章主要是對js獲取當前頁面路徑的示例代碼進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助

設置或獲取對象指定的“文件名”或路徑。 <script> alert(window.location.pathname) </script>   設置或獲取整個 URL 為字符串。 <script> alert(window.location.href);  </script>   設置或獲取與 URL 關聯的端口號碼。 <script> alert(window.location.port) </script>   設置或獲取 URL 的協議部分。 <script> alert(window.location.protocol) </script>   設置或獲取 href 屬性中在井號“#”後面的分段。 <script> alert(window.location.hash) </script>   設置或獲取 location 或 URL 的 hostname 和 port 號碼。 <script> alert(window.location.host) </script>   設置或獲取 href 屬性中跟在問號後面的部分。 <script> alert(window.location.search) </script>   網頁刷新推薦-JS <input type=button value=刷新 onclick="history.go(0)"> <input type=button value=刷新 onclick="location.reload()"> <input type=button value=刷新 onclick="location=location"> <input type=button value=刷新 onclick="location.assign(location)"> <input type=button value=刷新 onclick="document.execCommand('Refresh')"> <input type=button value=刷新 onclick="window.navigate(location)"> <input type=button value=刷新 onclick="location.replace(location)"> <input type=button value=刷新 onclick="document.URL=location.href">  
copyright © 萬盛學電腦網 all rights reserved