<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="+url)
</script>
js獲取當前url
1,設置或獲取對象指定的文件名或路徑。
alert(window.location.pathname)
2,設置或獲取整個 URL 為字符串。
alert(window.location.href);
3,設置或獲取與 URL 關聯的端口號碼。
alert(window.location.port)
4,設置或獲取 URL 的協議部分。
alert(window.location.protocol)
5,設置或獲取 href 屬性中在井號“#”后面的分段。
alert(window.location.hash)
6,設置或獲取 location 或 URL 的 hostname 和 port 號碼。
alert(window.location.host)
7,設置或獲取 href 屬性中跟在問號后面的部分。
alert(window.location.search)
8,獲取變量的值(截取等號后面的部分)
var url = window.location.search;
// alert(url.length);
// alert(url.lastIndexOf('='));
var loc = url.substring(url.lastIndexOf('=')+1, url.length);
9,用來得到當前網頁的域名
var domain = document.domain;
