Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save relyky/93e3ed710d56307aba42 to your computer and use it in GitHub Desktop.
Save relyky/93e3ed710d56307aba42 to your computer and use it in GitHub Desktop.
How to get “GET” request parameters in JavaScript?
參考自: http://stackoverflow.com/questions/831030/how-to-get-get-request-parameters-in-javascript
答案如下,只需解析出來。
window.location.search
解析函數
function getRequestParam(name){
if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search))
return decodeURIComponent(name[1]);
}
使用範例:
getRequestParam('foo');
將回傳其值(value)或"undefined"。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment