Thursday, January 24, 2013

Javascript query parameter setup

Using a query parameter can often be more convenient than having to change a hardcoded value while testing a script. This allows you to pass a variable into the script without having to edit and re-save your script.

var query = window.location.search.substring(1);
var keyVal = query.split("=");
var value = keyVal[1];
if (!value) { value = 100; } // in case no query parameter is passed in, use a default

No comments:

Post a Comment