前段时间遇到一道面试题。获取发送的数据,我知道应该通过地址栏来获取,但不知道该怎么做,所以用的简单的方法。
刚发现以为大神(Nihaorz)的博客里写了,在这里写上,以后机制他。
function getURLParameter(name){
return decodeURIComponent(
(new RegExp('[?|&]'+name+'='+'([^&;]+?)(&|#|;|$)')
.exec(location.search)||[,""])[1] //原来是用location.search获取地址栏的数据
.replace(/\+/g,'%20'))
||null;
}
var token=getURLParameter("token");