From: Mike Taylor Date: Thu, 22 May 2014 14:19:35 +0000 (+0100) Subject: Add optional URL parameter to mkws.getParameterByName function X-Git-Tag: 1.0.0~613 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=e1fb83ba0e792063cd05ae33f8d579a5ffe735a7;p=mkws-moved-to-github.git Add optional URL parameter to mkws.getParameterByName function --- diff --git a/src/mkws-core.js b/src/mkws-core.js index 0af84a9..7091291 100644 --- a/src/mkws-core.js +++ b/src/mkws-core.js @@ -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, " ")); }