Skip to content

[javascript] 取網址 get 的 值(key-value),get query key/value

Published: at 02:29 PM (1 min read)

紀錄一下 vanilla.js 取網址 get  key-value 的方法


[javascript]

function getQueryStringValue (key) { return decodeURIComponent(window.location.search.replace(new RegExp(”^(?:.*[&\\?]” + encodeURIComponent(key).replace(/[\.\+\*]/g, ”\\$&”) + ”(?:\\=([^&]*))?)?.*$”, “i”), “$1”)); }

[/javascript]

參考資料:

https://stackoverflow.com/questions/9870512/how-to-obtaining-the-querystring-from-the-current-url-with-javascript


Previous Post
[centOS] 安裝 phantomjs 錯誤,phantomjs: error while loading shared libraries: libfreetype.so.6: cannot open shared object file: No such file or directory
Next Post
[Nodejs] module.exports 與 exports 的差別