1, window.location.href 整个URl字符串(在浏览器中就是完整的地址栏)
返回值:http://www.cnblogs.com/Violet-sweet/articles/1740211.html
2,window.location.search 查询(参数)部分。除了给动态语言赋值以外,我们同样可以给静态页面,并使用 javascript来获得相信应的参数值
返回值:?ver=1.0&id=timlq
NO.1
String.prototype.GetValue= function(parm) {
var reg = new RegExp("(^|&)"+ parm +"=([^&]*)(&|$)");
var r = this.substr(this.indexOf("\?")+1).match(reg);
if (r!=null) return unescape(r[2]); return null;
}
function getName()
{
var url=location.href;
var name = url.GetValue("ID");
document.getElementById('name').innerHTML=name;
}
url.GetValue("ID"); ID为参数名称,返回name为参数值! ....html?ID=xxxx
NO.2
function getParameter(param)
{
var query = window.location.search;
var iLen = param.length;
var iStart = query.indexOf(param);
if (iStart == -1)
return "";
iStart += iLen + 1;
var iEnd = query.indexOf("&", iStart);
if (iEnd == -1)
return query.substring(iStart);
return query.substring(iStart, iEnd);
}
function getName()
{
var name = getParameter("ID");
document.getElementById('name').innerHTML=name;
}
getParameter ("ID"); ID为参数名称,返回name为参数值! ....html?ID=xxxx
来自http://www.cnblogs.com/Violet-sweet/articles/1740211.html