0

Possible Duplicate:
Why split the <script> tag when writing it with document.write()?

Browsing through some Chromium source (see line 45ff), I found:

in_script_tag: function(code) {
  return "<script>" + code + "</scr" + "ipt>";
},

Does anyone know why the author chose "</scr" + "ipt>" over "</script>"?

Community
  • 1
  • 1
Randomblue
  • 112,777
  • 145
  • 353
  • 547

2 Answers2

8

Inside a <script> tag </script> ends it, no matter where it occurs.

Example:

<script>
alert('</script>');
// anything here will not be executed anymore
</script>

The reason for this is simply that the browser does not know anything about JavaScript strings etc. so when it sees </script> it always closes the <script> tag.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
  • As a mod candidate, would you delete this question as it's a duplicate of a famous question? – gdoron Jun 17 '12 at 11:06
  • 1
    No, vote-to-close is sufficient. That's a case where I'll leave it to the community if they want to delete it or not. – ThiefMaster Jun 17 '12 at 11:08
  • And what is your personal stand? – gdoron Jun 17 '12 at 11:08
  • 1
    There's no need to delete it. While the title is not the best one the question is properly asked, has good answers and thus has some value. Besides that, I think it's much more important to delete *bad* content than *duplicate* content. – ThiefMaster Jun 17 '12 at 11:11
1

Because each time HTML parser sees the </script, it automatically considers the javascript fragment finished. )

raina77ow
  • 103,633
  • 15
  • 192
  • 229