From: Stevo on
David Mark wrote:
> Stevo wrote:
>> document.write("<h1>" + x + "</h1>");
>
> But if it is inline script, you need to escape the slash so the second
> string value isn't mistaken for a closing H1 tag.
>
> document.write("<h1>" + x + "<\/h1>");

But it *is* a closing H1 tag ;-) No mistaking about it. If it were a
closing script tag it would need escaping. I can't think of a single
environment where not escaping that would be a problem.
From: kangax on
On 2/20/10 4:49 PM, David Mark wrote:
> Stevo wrote:
>> joy99 wrote:
>>> (i) Suppose I write
>>> <script type="text/javascript">
>>> x="My Name"
>>> document.write("<h1>x</h1>);
>>> </script>
>>>
>>> would it show the result i.e., the string value of x in header 1?
>>> If not, how can I display the font values to my declared variables?
>>
>> Why ask the question? It's easier to try it than to find this group and
>> ask. Two minutes in notepad (or the equivalent simple text editor in
>> your favorite OS) and drag/drop it onto your favorite browser. If you
>> drop it onto Firefox, the error console will quickly show you the
>> trailing quote is missing after</h1>. It's nothing unique to JavaScript
>> that the code you've written would not use the x variable though. It's
>> just a letter in a string. You need to break out of the string, access x
>> and then resume the string:
>>
>> document.write("<h1>" + x +"</h1>");
>
> But if it is inline script, you need to escape the slash so the second
> string value isn't mistaken for a closing H1 tag.
>
> document.write("<h1>" + x +"<\/h1>");

Yeah, one of those things that standard and de-facto standard disagree
on. I've tested the whole slew of browsers�ancient, mobile, desktop,
etc.�and none would close the script tag on discovery of ETAGO. I guess
the cost of playing safe is not that big here, but it seems that any
implementation that goes against existing de-facto standard is doomed to
"break" half of the web, that's for sure :)

--
kangax
From: David Mark on
Stevo wrote:
> David Mark wrote:
>> Stevo wrote:
>>> document.write("<h1>" + x + "</h1>");
>>
>> But if it is inline script, you need to escape the slash so the second
>> string value isn't mistaken for a closing H1 tag.
>>
>> document.write("<h1>" + x + "<\/h1>");
>
> But it *is* a closing H1 tag ;-) No mistaking about it.

No it most assuredly is not a closing H1 tag. It's a string value in an
inline script.

> If it were a
> closing script tag it would need escaping. I can't think of a single
> environment where not escaping that would be a problem.

No need to think about it. Just do it.
From: Stevo on
David Mark wrote:
> Stevo wrote:
>> David Mark wrote:
>>> Stevo wrote:
>>>> document.write("<h1>" + x + "</h1>");
>>> But if it is inline script, you need to escape the slash so the second
>>> string value isn't mistaken for a closing H1 tag.
>>>
>>> document.write("<h1>" + x + "<\/h1>");
>> But it *is* a closing H1 tag ;-) No mistaking about it.
>
> No it most assuredly is not a closing H1 tag. It's a string value in an
> inline script.
>
>> If it were a
>> closing script tag it would need escaping. I can't think of a single
>> environment where not escaping that would be a problem.
>
> No need to think about it. Just do it.

Nike should expand their slogan to that :)
From: Thomas 'PointedEars' Lahn on
kangax wrote:

> On 2/20/10 4:49 PM, David Mark wrote:
>> But if it is inline script, you need to escape the slash so the second
>> string value isn't mistaken for a closing H1 tag.
>>
>> document.write("<h1>" + x +"<\/h1>");
>
> Yeah, one of those things that standard and de-facto standard disagree
> on.

How did you get the idea that invalid markup would be a de-facto standard?
A million flies can't be wrong?

> I've tested the whole slew of browsers—ancient, mobile, desktop,
> etc.—and none would close the script tag on discovery of ETAGO.

You need to test more, and refine your tests. The issue is known to occur
with "<script ...>...</script>" in particular, but it has been observed on
other occasions as well.

> I guess the cost of playing safe is not that big here, but it seems that
> any implementation that goes against existing de-facto standard is doomed
> to "break" half of the web, that's for sure :)

AISB.


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4
Prev: Thq Quiz
Next: How do I get keys from an associative array?