Add optional URL parameter to mkws.getParameterByName function
authorMike Taylor <mike@indexdata.com>
Thu, 22 May 2014 14:19:35 +0000 (15:19 +0100)
committerMike Taylor <mike@indexdata.com>
Thu, 22 May 2014 14:19:35 +0000 (15:19 +0100)
src/mkws-core.js

index 0af84a9..7091291 100644 (file)
@@ -111,10 +111,11 @@ mkws.M = function(word) {
 
 // This function is taken from a StackOverflow answer
 // http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript/901144#901144
-mkws.getParameterByName = function(name) {
+mkws.getParameterByName = function(name, url) {
+  if (!url) url = location.search;
   name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
   var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
-  results = regex.exec(location.search);
+  results = regex.exec(url);
   return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
 }