Language: JavaScript
Dynamically loading JSON2.js if not loaded
if (!JSON) { // Autoload JSON2.js if possible // Note: if using a script loader you may have to explicitly load json2.js // assumes loading from same folder as this script var scripts = $("script"); var src = null; scripts.each(function (i) { src = $(this).attr("src"); if (src && src.toLowerCase().indexOf("serviceproxy.") > -1) { src = src.toLowerCase(); src = src.substr(0, src.indexOf("serviceproxy.")) + "json2.min.js"; return false; } }); $("<script>").attr("src", src).attr("type", "text/javascript").appendTo("head"); } // another option - based on last script loaded - simpler, but less reliable if (!JSON) { // Autoload JSON2.js if possible var script = $("script").last(); var src = script.attr("src").toLowerCase(); var src = src.substr(0, src.indexOf('serviceproxy.')) + "json2.min.js"; $("<script>").attr("src", src).attr("type", "text/javascript").appendTo("head"); }
Tags:
Report Abuse
Subscribe
Discuss
News
About
New Snippet
Recent Snippets
My Snippets
Favorites
Web Code
Search
Copy
Line#