How to get the parameter value or key value on the the window location (page URL)? If you have this URL “examplesite.com/?debug=1” and thinking how to get the value of debug parameter, the codes below is the answer.
jQuery( document ).ready( function($){ // Example URL is examplesite.com/?debug=1 var getPostValue = function getPostValue(key) { var pageURL = decodeURIComponent(window.location.search.substring(1)), URLvar = pageURL.split('&'), keyName, i; for (i = 0; i < URLvar.length; i++) { keyName = URLvar[i].split('='); if (keyName[0] === key) { return keyName[1] === undefined ? true : keyName[1]; } } }; if( getPostValue( 'debug' ) ){ // your codes } });
Leave a Reply