location對象
location是最有用的 BOM 對象之一,它提供了與當前窗口中加載的文檔有關的信息,還提供了一些導航功能。
location對象是很特別的一個對象,因爲它既是 window對象的屬性,也是document 對象的屬性;換句話說, window.location和 document.location引用的是同一個對象。
<script>
function getQueryStringArgs() {
var qs = (location.search.length > 0 ? location.search.substring(1) : "");
args = {};
items = qs.length ? qs.split("&") : [];
item = null;
name = null;
value = null;
i = 0;
len = items.length;
for(i = 0; i < len;i++){
item = items[i].split("=");
name = decodeURIComponent(item[0]);
value = decodeURIComponent(item[1]);
if(name.length){
args[name] = value;
}
}
return args;
}
</script>