js獲取當(dāng)前頁面的url網(wǎng)址信息
更新時間:2014年06月12日 15:26:07 投稿:whsnow
這篇文章主要介紹了通過js如何獲取當(dāng)前頁面的url網(wǎng)址信息,需要的朋友可以參考下
1、設(shè)置或獲取整個 URL 為字符串:
window.location.href
2、設(shè)置或獲取與 URL 關(guān)聯(lián)的端口號碼:
window.location.port
3、設(shè)置或獲取 URL 的協(xié)議部分
window.location.protocol
4、設(shè)置或獲取 href 屬性中跟在問號后面的部分
window.location.search
5、獲取變量的值(截取等號后面的部分)
var url = window.location.search;
// alert(url.length);
// alert(url.lastIndexOf('='));
var loc = url.substring(url.lastIndexOf('=')+1, url.length);
6、設(shè)置或獲取 URL 的協(xié)議部分:
window.location.protocol
7、設(shè)置或獲取 href 屬性中在井號“#”后面的分段:
window.location.hash
8、設(shè)置或獲取 location 或 URL 的 hostname 和 port 號碼:
window.location.host
window.location.href
2、設(shè)置或獲取與 URL 關(guān)聯(lián)的端口號碼:
window.location.port
3、設(shè)置或獲取 URL 的協(xié)議部分
window.location.protocol
4、設(shè)置或獲取 href 屬性中跟在問號后面的部分
window.location.search
5、獲取變量的值(截取等號后面的部分)
復(fù)制代碼 代碼如下:
var url = window.location.search;
// alert(url.length);
// alert(url.lastIndexOf('='));
var loc = url.substring(url.lastIndexOf('=')+1, url.length);
6、設(shè)置或獲取 URL 的協(xié)議部分:
window.location.protocol
7、設(shè)置或獲取 href 屬性中在井號“#”后面的分段:
window.location.hash
8、設(shè)置或獲取 location 或 URL 的 hostname 和 port 號碼:
window.location.host
相關(guān)文章
學(xué)習(xí)drag and drop js實現(xiàn)代碼經(jīng)典之作
今天讀John Resig的Pro Javascript Techniques時候看到他書上給的一個關(guān)于drag and drop的例子, 合上書本自己寫一個簡化版本的。大約20分鐘完成, 沒有考慮兼容firefox。整個代碼封裝成一個對象 也是借鑒書中的風(fēng)格。我覺得很好。2009-04-04
解決layui的table插件無法多層級獲取json數(shù)據(jù)的問題
今天小編就為大家分享一篇解決layui的table插件無法多層級獲取json數(shù)據(jù)的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09
JS中const對于復(fù)雜類型變量和普通類型變量的區(qū)別詳解
我們在開發(fā)的過程中一定常常發(fā)現(xiàn)const關(guān)鍵字定義的簡單類型變量不可以改變,但是你如果定義的是一個復(fù)雜類型變量(比如對象)的話對里面屬性的增刪改查是可以的,那這又是為什么呢,接下來就來和小編一起探討一下吧2023-11-11
JavaScript通過代碼調(diào)用Flash顯示的方法
這篇文章主要介紹了JavaScript通過代碼調(diào)用Flash顯示的方法,實例分析了JavaScript通過flash插件swfobject.js調(diào)用flash顯示的具體操作技巧,需要的朋友可以參考下2016-02-02
4種JavaScript實現(xiàn)簡單tab選項卡切換的方法
這篇文章主要介紹了4種JavaScript實現(xiàn)簡單tab選項卡切換的方法,感興趣的小伙伴們可以參考一下2016-01-01

