SyntaxError: unterminated string literal javascript

I get a JavaScript error in my browser whenever I try 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 these two lines? and if possible, how to fix it?

thank you for your time

+6
source share
1 answer

You cannot insert a substring </script> anywhere in a script block.

Change the call to document.write :

 <script> window.jQuery || document.write('<script src="<%=request.getContextPath()%>/resources/jq/jquery-1.10.2.min.js"></' + 'script>') </script> 

The browser “parses” the contents of the <script> , blindly looking for the closing </script> , ignoring the syntax of the content.

+16
source

Source: https://habr.com/ru/post/957426/


All Articles