1、這段JS代碼怎麼修改才能獲取來路域名
字元串處理下
strLength = document.referrer.length ;
strUrl = document.referrer.substring( 7 , strLength ) ;
strUrl = strUrl.substring( 0 , strUrl . indexOf("/") )
document.write( strUrl );
函數說明
str.Length -------------------返回字元串總長度
str.substring( start_Index, stop_Index ) -----------------截取指定區間字元串
str.indexOf( child_str ) -------------------------返回子字元串第一次在str中出現的位置的
2、用js如果獲取域名中的頁面名字?
利用js中window對象的location子對象的pathname屬性,返回url所對應的網頁文件的虛擬路徑,其中包括網頁文件的文件名。用法如下:
var str = window.location.pathname
在你舉的例子中少了個埠號應該http://hostname:port/index.html
這時str 的值就為 /index.html
如果目錄更深如http://hostname:port/wtccut/index.html
那麼str 的值就為 /wtccut/index.html
str為網頁文件的虛擬路徑,如果不是你要的值你可以通過正則表達式繼續截取。
你可以用
var str = window.location.hostname 獲得主機名或ip地址
var str = window.location.port 獲得埠號
3、javascript中怎麼獲取主機的域名和埠號
方法 步驟如下:
打開開發工具。比如editplus、dw等
新建一個html文件,寫入腳本標簽
<script language="javascript" type="text/javascript">
<!--
//-->
</script>
js代碼必須寫入好改標簽中。
3.想要獲取web的主機名和埠號就必須使用window下的location對象的屬性才行的。
4.獲取主機域名:
location.hostname
獲取埠號
location.port
具體實現的代碼:
function f1(){
alert(window.location.hostname);
alert(window.location.port);
}
4、JavaScript獲取當前域名
<input type="text" style=" width:300px;" name="new" id=new">
<script>var nurl = document.referrer;//來源url
document.URL //獲取當前域名
document.title//獲取當前頁面標題
我是愛分享資源網的站長,如果你覺得不錯請訪問下我的網站,謝謝了!
5、如何用js獲取地址欄的URL的域名
<input type="text" style=" width:300px;" name="new" id=new">
<script>
var nurl = document.referrer;//來源url
document.URL //獲取當前域名
document.title//獲取當前頁面標題
document.getElementById('new').innerHTML = nurl;</script>
我是愛分享資源網的站長,如果你覺得不錯請訪問下我的網站,謝謝了!
6、如何通過js獲取當前訪問頁面的域名
<input type="text" style=" width:300px;" name="new" id=new">
<script>
var nurl = document.referrer;//來源url
document.URL //獲取當前域名
document.title//獲取當前頁面標題
document.getElementById('new').innerHTML = nurl;</script>
我是愛分享資源網的站長,如果你覺得不錯請訪問下我的網站,謝謝了!
7、js 獲取二級域名 已知var a="http://abc.baidu.com" 匹配獲得結果abc
var a="http://abc.網路.com";a = a.split(".")[0];a = a.split("//")[1];結果就是a == "abc";
8、js獲取當前網頁地址並去掉域名
用正則表達式啊
獲取當前網址的url
var url=window.location.href; 然後使用正則表達式匹配,這個你要懂正則表達式,具體可以當網上搜索一下,如果這個網址裡面只有一個問號的話,那麼還有一個簡單的方法,如下
以問號分割,將返回一個數組,數組裡面有兩個元素
var newurl=url.split('?')[1];
newurl0],獲得是問號以前的字元串,就是http://.baidu.com/new
newurl[1],自然是word=js
列印下結果
alert(newurl[1])
希望是你要的答案啦
9、如何使用Javascript獲取一個鏈接地址中的頂級域名
試試:tls.js
主頁:https://github.com/oncletom/tld.js
數據和Mozilla同步。
用法:
var tld = require('tldjs');10、JS獲取域名的值
你說的是欄目id 還是項目的id
?