I created code to get the URL parameter. I would just like to have a unique task for this function, not the implementation of the result, that the responsibilities will belong to other future functions.
I searched for various internet search combinations, like "get javascript return", "get function result", or something. But without success! In the end, it has to make the function have only one task in order to be manipulated by other functions.
function getURL(){
var getURLs = window.location.search.substring(1).split('&');
var getURLArray = {};
for(var i=0; i<getURLs.length; i++) {
var getURL = getURLs[i].split('=');
getURLArray[getURL[0]] = getURL[1];
}
action = getURL[0] ;
}
The purpose of the function is to just get the value of the parameter, without having to use global variable or Storage API (localStorage or sessionStorage).
return actionat the end of thatfunction.getURL[0]- P.S. dont' declare a variable inside a for loop that you want to use outside of it - while this works withvar, it's not good practicereturn = myResult;- this isn't VB6 ... it's likereturn xxxxwherexxxxis the value you want to return, as a literal or a variable