Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 429
MChan Avatar asked Nov 05 '13 13:11

MChan


1 Answers

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.

like image 123
Pointy Avatar answered Sep 20 '22 07:09

Pointy