Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8541565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:51:39+00:00 2026-06-11T11:51:39+00:00

Consider the following html document: <!DOCTYPE html> <html> <head> <script type=text/javascript> alert(Hello) </script> </head>

  • 0

Consider the following html document:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
alert("Hello")
</script>
</head>
</html>

The result of opening in Firefox, Safari and Chrome is the same in my macbook: an alert message displays “Hello”. I was reading this answer to try to understand the behavior of the browers. The main part is:

Since the contents of tags are treated as CDATA, the contents are not parsed and you can store unquoted XML or HTML in the contents (as long as you don’t ever put a </script> tag in the contents, since that will close your element).

Lets try what happens when we see the source in Firefox:

source code screenshot with </script> in the alert call

The output in the browser it shows is ") since it thinks that the script tag was closed
inside alert. One way to overcome this in case we really, really want to display "</script>" is to do:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
alert("<"+"/script>")
</script>
</head>
</html>

Now Firefox understands it:

source code screenshot with "</" + "script>" in the alert call

Question:

It is really simple for the parser to check if </script> is the closing part. It does take more
time to check this but it is doable (count the number of quotes before the encounter of </script>. If it is even then it is the closing tag, otherwise continue looking for the closing tag). The question is, is this a rule that we cannot write "</script>" inside javascript? If so, what other subtle rules are out there that I might not be aware of?

The same goes for say php parsers. <?php echo "?>" ?>. I have tested this and php seems to know where the real ?> is located.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:51:40+00:00Added an answer on June 11, 2026 at 11:51 am

    Correct, you cannot write "</script>" within inline Javascript, but you can write "<\/script>". In an external Javascript file, you don’t have that limitation.

    The Javascript engine will see "</script>" as the end of the script, regardless of the context it appears.

    As long as you are using HTML and not XHTML, that is the only real gotcha.

    XHTML, served as an XHTML file[1] has a few more gotchas, including -- being the beginning and end of XHTML comment.

    [1] Very little XHTML stuff is actually served XHTML. It us usually served as HTML and then processed by a tag-soup parser than can make sense of everything from HTML comments embedded and even CDATA tags that don’t belong.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following html snippet <!DOCTYPE html> <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-1.4.2.js ></script> <script
Consider the following document <html> <body> This is some content <script type=text/javascript src=verySlowToRespond.js></script> This
Consider the following code: <!DOCTYPE html> <html> <body> <script type=text/javascript> var str = '<12>
Consider the following example: <html> <body> <script type=text/javascript> var str=filename.jpg; var pattOne = new
Consider the following HTML: (Written for Google Chrome) <html> <head> <script language=javascript> function AddToIFrame(){
Consider a document in the following format: <!DOCTYPE html> <html> <head> <title></title> <body> <div
Consider the following code: index.html <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd> <html> <head>
Consider the following HTML table: <table id=myTable1> <tr id=TR1> <td><input type=text id=quantity1 name=quantity1 /></td>
Please consider the following scenario with a simple HTML document and a JavaScript loaded
Consider the following Html file: <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd> <html> <head>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.