setec setec - 1 year ago 64
Javascript Question

Why js can't understand string '</script>'?

I have a simple javascript (jsFiddle):


Browser fails to understand it.

This is console output:

Uncaught SyntaxError: Unexpected token ILLEGAL

But this script works (jsFiddle):

alert('</scriptt>');//shows alert text '</scriptt>'

Is it some kind of browser bug or normal

(browser is Chrome)

Answer Source

Because it is considered as:


which is a SyntaxError

You can use

alert( '<\/script>\n');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download