Forum Moderators: open

Message Too Old, No Replies

Someone really explain this--> '</'+'script>'

         

smumdax

11:35 pm on Nov 28, 2003 (gmt 0)

10+ Year Member



I'm trying to find the answer somewhere, but cherching for the above on Google obviously ain't givin much results.

Could anyone explani why we must do this somtimes? No dumb short explnation like "That's how it is." I really want an complete and accurate answer, if better a link to some big explanation.

Thanks,

Smumdax

jatar_k

12:44 am on Nov 29, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld smumdax,

I have to admit I am not really sure what you want to understand, could you clarify?

Enigma

1:08 am on Nov 29, 2003 (gmt 0)

10+ Year Member



Where have you seen that smumdax, which context?

choster

3:46 am on Nov 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Suppose you were doing something like

<script type="text/javascript">
function doStuff {...}
document.write("<script src='import.js'></script>");
function doOtherstuff {...}
</script>

Some "helpful" browsers interpret the inner </script> (i.e. inside the document.write) as closing the actual <script>-- thus, doOtherstuff would never get processed. To get around this, the inner </script> is split up into two pieces-- "</" and "script>"-- so the browser never "sees" </script> until it needs to.

I haven't had to do this in a long time, so I don't even remember which browsers had this problem. If I had to guess it was probably to deal with one of the 4th generation IEs for Macintosh.

RonPK

9:22 pm on Nov 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



IIRC the proper way to work around this is to escape the / in </script> with a \.

smumdax

6:00 pm on Nov 30, 2003 (gmt 0)

10+ Year Member



Thanks for the short answers. Anyone has a link to some complete explanation with a list of the borwsers that do this?

Just for the records, I have IE6 on WinXP and the "problem" happens here also.... so it doesn't seem to be a rare thing on old Mac browsers...

Smumdax

DrDoc

4:07 pm on Dec 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



complete explanation

Well, it's just part of the whole HTML standard. A script section is, by definition, started by:
<script type="whatever">
and ended by:
</script>

So, the browser will simply look for the first occurance of </script> and assume that's where the script ends.

The same goes for everything. For example:

<!-- This is a comment...
Does it end here... -->
...or here? -->

Of course the comment is going to end after the first -->, 'cause that's what the definition of comments says.

What about this, then:

<textarea></textarea></textarea>

Not that it's valid HTML (you can't put other tags inside the text area element... but I'm doing it anyway, just to demonstrate)... But it seems obvious that the first </textarea> tag marks the end of the textarea element ('causing an invalid closing </textarea>)

That brings us back to:

<script>
document.write("</script>");
</script>

Oh, but you may say that the browser is supposed to be smart enough to realize that the tag is in the middle of a quotation.

Hmm, then what about this?

<p>The widget is 43" long.</p>

Since the double quote is not replaced by &quot; (like it should be), is the </p> tag supposed to be "inside a quotation"? :)

I could go on and on, but I think this explains it fairly well...

smumdax

5:43 pm on Dec 1, 2003 (gmt 0)

10+ Year Member



Great explanation!

If we could always get great answers like that when needed, wouldn't the world be... easier?

Thanks a lot.

DrDoc

5:46 pm on Dec 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're welcome! And, welcome to Webmaster World! :)