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

by 清泉 8. 七月 2009 18:09
如果获取“当前”域名
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;
}

Tags:

JS相关技术

评论

添加评论



(将显示你的Gravatar头像)  

biuquote
微笑得意调皮害羞酷大笑惊讶发呆喜欢可怜尴尬闭嘴噘嘴皱眉伤心抓狂呕吐坏笑漫骂发怒
Loading



Supidea.com 晨飞的梦 @ All Rights Reserved. Powered by BlogYi.NET ver:1.8.0.0. 苏ICP备09011404号

关于博主

kamau
抱着美好的理想背井离乡,这酸甜苦辣只能默默忍受。既然选择了路,就得风雨兼程……

Calendar

<<  二月 2012  >>
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

在日历中查看文章

最近的评论

Comment RSS

声明

      本博所发一切破解相关附件只作学习研究交流之用,严禁用于商业用途,请在下载24小时内删除。
      本博所有网友评论不代表本博立场,版权归其作者所有。

© Copyright 2009