<script>
alert(location.hostname)
alert(location.port)
alert(location.pathname)
alert(location.search)
</script>
<script>
function winsx(url) //URL传递的参数
{
var winurl =url?url:(unescape(window.location.href));
var wlp = winurl.split("?")[1];
var wincs = wlp.split("&");
for(var i=0; i<wincs.length; i++)
{
var tur = wincs[i].split("=");
eval('this.'+tur[0]+'="'+tur[1]+'";');
}
}
var ug = new winsx("http://www.yourname.com/aa/bb.php?val=11&test=2");
alert(ug.val)
alert(ug.test)
</script>
还有一种稍有些复杂的取域名的方法,也是过滤了文件夹名,文件名,参数……
var getHost = function(url)
{
var host = "null";
if(typeof url == "undefined"|| null == url)
{
url = window.location.href;
}
var regex = /.*\:\/\/([^\/]*).*/;
var match = url.match(regex);
if(typeof match != "undefined" && null != match)
{
host = match[1];
}
return host;
}