萬盛學電腦網

 萬盛學電腦網 >> 腳本專題 >> javascript >> 兩種js獲取當前域名代碼

兩種js獲取當前域名代碼

 今天給各位朋友介紹兩種js獲取當前域名

 代碼如下
//獲取當前域名

1、window.location.host;
2、document.domain;

//獲取當前頁面地址

url = window.location.href;
 

例子

 代碼如下
<script language="javascript">
//獲取域名
host = window.location.host;
host2=document.domain;

//獲取頁面完整地址
url = window.location.href;

document.write("<br>host="+host)
document.write("<br>host2="+host2)
document.write("<br>url="+ur(www.45it.net)l)
</script>
 

補充:

獲取當前域名信息

 代碼如下
thisTLoc = top.location.href;
thisPLoc = parent.document.location;
thisTHost = top.location.hostname;
thisHost = location.hostname;
strwrite = ” thisTLoc: [" + thisTLoc + "]”
strwrite += ” thisPLoc: [" + thisPLoc + "]”
strwrite += ” thisTHost: [" + thisTHost + "]”
strwrite += ” thisHost: [" + thisHost + "]”
document.write( strwrite );

copyright © 萬盛學電腦網 all rights reserved