简体   繁体   中英

SyntaxError: unterminated string literal javascript

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM