如何使用JS來獲取當前頁面位址資訊

2021-08-03 05:02:51 字數 880 閱讀 5950

設定或獲取物件指定的檔名或路徑。

alert(window.location

.pathname)

設定或獲取整個 url 為字串。

alert(window.location

.href);

設定或獲取與 url 關聯的埠號碼。

alert(window.location

.port)

設定或獲取 url 的協議部分。

alert(window.location

.protocol)

設定或獲取 href 屬性中在井號「#」後面的分段。

alert(window.location

.hash)

設定或獲取 location 或 url 的 hostname 和 port 號碼。

alert(window.location

.host)

設定或獲取 href 屬性中跟在問號後面的部分。

alert(window.location

.search)

獲取變數的值(擷取等號後面的部分)

var url = window.location

.search

;// alert(url.length);

// alert(url.lastindexof('='));

var loc = url.substring(url.lastindexof('=')+1, url.length);

059 獲取當前頁面位址

1.window.location物件可用於獲取當前頁面位址 url 並把瀏覽器重定向到新頁面。2.window.location.href屬性返回當前頁面的url。3.window.location.hostname屬性返回 當前頁面的 網際網路主機的名稱。4.window.location.pa...

Magento獲取當前頁面URL位址

magento獲取當前頁面url位址 在magento中,可以通過core url助手類中的getcurrenturl 方法獲取當前頁面的url位址 currenturl this helper core url getcurrenturl 在社會化分享中,當前頁面的url位址非常有用 helper...

JS獲取當前頁面頁面URL資訊

url即 統一資源定位符 uniform resource locator,url 完整的url由這幾個部分構成 scheme host port path?query fragment scheme 通訊協議 常用的http,ftp,maito等 設定或獲取url從頭到埠號部分。url windo...