Simple Way to Extract GET Params from a JavaScript Script Tag
loopj.com
loopj.com
var getErrorLocation = function (error) {
var loc, replacer = function (stack, matchedLoc) {
loc = matchedLoc;
};
if ("fileName" in error) {
loc = error.fileName;
} else if ("stacktrace" in error) { // Opera
error.stacktrace.replace(/Line \d+ of .+ script (.*)/gm, replacer);
} else if ("stack" in error) { // WebKit
error.stack.replace(/at (.*)/gm, replacer);
loc = loc.replace(/:\d+:\d+$/, ""); // remove line number
}
return loc;
};
You could use it as such: try {
0();
} catch (e) {
var scriptLocation = getErrorLocation(e);
}
In SpiderMonkey and Rhino, the Error constructor itself is magic too, so you could just do getErrorLocation(new Error) instead. AddHandler server-parsed .js
then add: (function(query_string){
...
})("<!--#echo var="QUERY_STRING" -->");
around your script. This obviously has problems with caching, but it doesn't have the problems addressed with those "heavy loads" that you have with PHP et al. scripts=document.elements.getElementByTagName('script')
latest=scripts[scripts.length-1]This approach allows you to specify parameters as JSON. So data of arbitrary length can be passed without having to resort to some global variable.
It solves a problem I had where I needed to pass some template engine generated content into an otherwise static script.
Thanks for the tip :)
example usage: <script src="scriptaculous.js?load=effects,dragdrop"></script>
code is here: http://script.aculo.us/scriptaculous.js
If you're familiar with Django, this is why the GET, POST and other request dictionaries are actually MultiValueDicts. If you call request.GET.getlist('varname') instead of request.GET['varname'], you'll get a list of each value passed with that name. The brackets aren't special, and if you used them, you'd need request.GET.getlist('varname[]').
http://www.onlineaspect.com/2009/06/10/reading-get-variables...
<meta name=key content=123/>