window.location.href |
整个URl字符串(在浏览器中就是完整的地址栏)
|
window.location.protocol |
URL 的协议部分
返回值:http:
|
window.location.host |
URL 的主机部分(带端口号)
|
window.location.port | URL 的端口部分。 |
window.location.pathname | URL 的路径部分(就是文件地址) |
window.location.search | 查询(参数)部分。获得的是url中?部分。除了给动态语言赋值之外,咱们一样能够给静态页面,并使用javascript来得到相信应的参数值 |
window.location.hash | 锚点。获得的是url中#部分。 |
function getQueryString(name) {
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
//substr(1) :从1位置开始,驱动 '?' 号
//macth(reg):匹配正则表达式
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
return null;
}