I am getting a JavaScript error in my browser whenever I am trying to add the following two lines in the section of my application home page:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="<%=request.getContextPath()%>/resources/jq/jquery-1.10.2.min.js"></script>')</script>
Can someone please tell me what is wrong in those two lines? and if possible how to fix it?
Thanks for your time
You can't embed the substring </script>
anywhere within a script block.
Change your document.write
call:
<script>
window.jQuery ||
document.write('<script src="<%=request.getContextPath()%>/resources/jq/jquery-1.10.2.min.js"></' + 'script>')
</script>
The browser "parses" <script>
tag contents by blindly searching for a closing </script>
tag, paying no attention whatsoever to the syntax of the contents.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With