Skip to content

Instantly share code, notes, and snippets.

@RhinoLu
Created September 23, 2014 11:30
Show Gist options
  • Save RhinoLu/96c37558a1d75c463468 to your computer and use it in GitHub Desktop.
Save RhinoLu/96c37558a1d75c463468 to your computer and use it in GitHub Desktop.
獲取網址參數 url parameter
// http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
var prodId = getParameterByName('prodId');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment