Last active
August 29, 2015 14:20
-
-
Save relyky/93e3ed710d56307aba42 to your computer and use it in GitHub Desktop.
How to get “GET” request parameters in JavaScript?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
參考自: 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