JS取URL域名,文件名,参数

以下是代码片段:

<SCRIPT>
//scheme://host:port/path?query#fragment
alert(location.hostname)
alert(location.port)
alert(location.pathname)
alert(location.search)
</SCRIPT>
<SCRIPT><BR>
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>

 

<script language=javascript>
<!--
function queryString(sParam){
var sBase = window.location.search
var re = eval("/" + sParam + "=([^&]*)/")
if (re.test(sBase)){
return RegExp.$1
}
else{
return null
}
}
alert(queryString("id"))
//-->
</script>

 

 

以下是代码片段:

///Page.QueryString[]

function QueryString(fieldName)
{  
      var urlString = document.location.search;
      if(urlString != null)
      {
           var typeQu = fieldName+"=";
           var urlEnd = urlString.indexOf(typeQu);
           if(urlEnd != -1)
           {
                var paramsUrl = urlString.substring(urlEnd+typeQu.length);
                var isEnd =  paramsUrl.indexOf('&');
                if(isEnd != -1)
                {
                     return paramsUrl.substring(0, isEnd);
                }
                else
                {
                    return paramsUrl;
                }
           }
           else 
           return null;
      }
     else
     return null;
 }
 

 

版权声明:
作者:Kiyo
链接:https://www.wkiyo.cn/html/2008-01/i290.html
来源:Kiyo's space
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>