1

Here's the entire document that causes the error in Firefox and Chrome:

<!DOCTYPE html>
<html>
<head>
    <script>
        var strs = [], scripts = ['harbl.js'], s = 0;
        strs.push('<script src="' + scripts[s] + '"></script>');
    </script>
</head>
<body>
    <p>buh...</p>
</body>
</html>

http://jsfiddle.net/cryptoquick/J4zZT/

The error I get is:

Uncaught SyntaxError: Unexpected token ILLEGAL 

This has me really puzzled.

Hunter Beast
  • 782
  • 7
  • 17

3 Answers3

9

The </script> literal is parsed by the browser as it's not aware of the context when traversing your code. You have to escape it like so : <\/script>. It's a known problem.

Tim Lamballais
  • 1,056
  • 5
  • 10
3

Change it to:

strs.push('<script src="' + scripts[s] + '"></s' + 'cript>');
Ian
  • 50,146
  • 13
  • 101
  • 111
-1

Front Slash '/' is considered as special character . It's the cause for the error .

strs.push('<script src="' + scripts[s] + '"><\/script>');

Please read this post for more information JavaScript and forward slashes in strings .

Community
  • 1
  • 1
kannanrbk
  • 6,964
  • 13
  • 53
  • 94