文档库 最新最全的文档下载
当前位置:文档库 › js取得当前url,javascript获取当前页面url值,js获取域名-

js取得当前url,javascript获取当前页面url值,js获取域名-

js取得当前url,javascript获取当前页面url值,js获取域名-
js取得当前url,javascript获取当前页面url值,js获取域名-

js取得当前url,javascript获取当前页面url值,js获取域名-

js取得当前url,javascript获取当前页面url值,js获取域名

分类:JS 2010-09-01 14:14

如果获取“当前”域名

host = window.location.host;

url=document.domain;

url = window.location.href;

取得完整url路径: 用以下代码可以完整研证结果: thisDLoc = document.location;

thisURL = document.URL;

thisHREF = document.location.href;

thisSLoc = self.location.href;

thisTLoc = top.location.href;

thisPLoc = parent.document.location;

thisTHost = top.location.hostname;

thisHost = location.hostname; 还有一种稍有些复杂的取域名的方法,也是过滤了文件夹名,文件名,参数

……

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;

}

相关文档