traq
11-16-2010, 03:59 AM
Hi,
I need to check if jQuery is loaded on a page, and (if not) write a script tag to load it. I found this (http://forum.jquery.com/topic/cdn-failover-to-domain-provided-js-files) suggestion by John Resig:
<script>
if(typeof jQuery === "undefined"){
document.write('<script src="local/jquery.js"></script>');
}
</script>makes sense. And, looking at the discussion, it seems that it works for others.
However, when I run it, I get this as the page output:
");and a javascript error
unterminated string literal
it seems that the </script> tag - inside the literal string - is being treated as an actual closing script tag, instead of as a string. I've tried switching around double- and single-quotes, to no avail. Any suggestions?
I need to check if jQuery is loaded on a page, and (if not) write a script tag to load it. I found this (http://forum.jquery.com/topic/cdn-failover-to-domain-provided-js-files) suggestion by John Resig:
<script>
if(typeof jQuery === "undefined"){
document.write('<script src="local/jquery.js"></script>');
}
</script>makes sense. And, looking at the discussion, it seems that it works for others.
However, when I run it, I get this as the page output:
");and a javascript error
unterminated string literal
it seems that the </script> tag - inside the literal string - is being treated as an actual closing script tag, instead of as a string. I've tried switching around double- and single-quotes, to no avail. Any suggestions?