分享

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

 闪宁斯达 2010-09-02

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;
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多