js keeps translating "<" as "&lt;"

R

rynato

OK this may well be a stupid question but I am completely stumped:

I have a line of code that reads like this:

slideHTML+='<img src="'+this.postimages[picindex].src+'"
border="'+this.imageborder+'px" />';

when js writes out this bit of code, it appears like this when I look
at 'generated code' in Firefox:

&lt;img src= [blah blah blah] &gt;

which, of course, is parsed by the browser as a string of text rather
than as an HTML tag.

I tried using escape characters, I tried using unescape("%3C"), I
tried everything I could think of to get javascript to spit out a '<'
and a '>' instead of their HTML entities.

This is in an XHTML 1.1 document, and only appears in browsers which
apply XHTML rules rather strictly, like FF2 and Safari 3. IE6, bless
its black little heart, doesn't have a problem with it.

Any clues, anybody? Thanks in advance.
 
T

Thomas 'PointedEars' Lahn

rynato said:
I have a line of code that reads like this:

slideHTML+='<img src="'+this.postimages[picindex].src+'"
border="'+this.imageborder+'px" />';

when js writes out this bit of code, it appears like this when I look at
'generated code' in Firefox:

&lt;img src= [blah blah blah] &gt;

which, of course, is parsed by the browser as a string of text rather
than as an HTML tag.

It is rather vice-versa: you have created text that is then converted into
HTML, and you see the result of that conversion with "View Generated Source".

You have not posted how exactly you are trying to "write[...] out this bit
of code" (JS does not do it but the DOM does, as only *caused* by JS), but
ISTM you are manipulating a text node in which case the behavior you
observed is perfectly normal. A text node is a text node is a text node :)

So you are probably looking for

var img = document.createElement("img");

/*
* insert alternative text here or leave it blank if the image conveys
* no information to the reader
*/
img.alt = "...";

img.src = this.postimages[picindex].src;
img.style.border = "0";
document.body.appendChild(img);

instead. The usual feature tests should be applied at runtime:

http://www.jibbering.com/faq/faq_notes/not_browser_detect.html
I tried using escape characters, I tried using unescape("%3C"),

escape() and unescape() are for URLs and similar data such as cookies. (And
nowadays, you better use encodeURI(), encodeURIComponent(), decodeURI() and
decodeURIComponent(), respectively.)
I tried everything I could think of to get javascript to spit out a '<'
and a '>' instead of their HTML entities.

Apparently you did not.
This is in an XHTML 1.1 document,

Then why are you even using XHTML and XML syntax?

http://hsivonen.iki.fi/xhtml-the-point/
http://www.hixie.ch/advocacy/xhtml

Please have a look at my signature, too.
and only appears in browsers which apply XHTML rules rather strictly,
like FF2 and Safari 3. IE6, bless its black little heart, doesn't have a
problem with it.

Internet Explorer (any version) does not support XHTML to date which is why
you should not use XHTML on the Web unless absolutely required, and then a
HTML version for HTML UAs and an XHTML version for XHTML UAs as
"HTML-compatible XHTML" is based on a misconception.

Safari 3.0.3 is still beta quality, so unless you tested with Safari 3.0.4
on the Mac, your test result does not account for anything.

Of the UAs you named, I know of only Firefox 2 to use a (non-validating)
XML parser for XHTML markup, and only if served with an XML media type,
preferably application/xhtml+xml as specified.


PointedEars
 
R

rynato

I tried everything I could think of to get javascript to spit out a '<'
Apparently you did not.

Um, no, actually I did try everything I could think of, which is why
when I finally reached a dead end, I resorted to posting my query here
and taking my chances of receiving condescending, snotty, arrogant
replies from folks who were obviously born knowing everything.
 
R

rynato

Safari 3.0.3 is still beta quality, so unless you tested with Safari 3.0.4
on the Mac, your test result does not account for anything.

I did, in fact, test with Safari 3.0.4.

So, did you go to school to be an arrogant asshole or were you just
born that way?
 
T

Thomas 'PointedEars' Lahn

Randy said:
rynato said the following on 11/17/2007 11:04 AM:
I did, in fact, test with Safari 3.0.4.

So, did you go to school to be an arrogant asshole or were you just
born that way?

rynato, meet Thomas, the resident Troll. [further insults]

You really don't know what a troll is because if you did, in an objective
analysis you would find out that you qualify as one. As you have seldom,
if ever, anything substantial to say, and you resort to insults of the
lowest possible level very quickly when you run out of arguments in your
mostly irrational kind of argumentation, if that.

But it figures that you would make an attempt to solidarize with an
individual who showed the aforementioned dissocial behavior in response
to also my followup that not only attempted to cleared up many of his
misconceptions but also actually provided a helpful answer; much in
contrast to yours, I should add.

It also figures that you are not even taking the possibility into account
that you were meant as well with "... folks" given your extremely short and
destructive answer. I can only find that amusing.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Randy said:
Thomas 'PointedEars' Lahn said the following on 11/17/2007 3:39 PM:
Randy said:
rynato said the following on 11/17/2007 11:04 AM:
On Nov 17, 4:06 am, Thomas 'PointedEars' Lahn <[email protected]>
wrote:
Safari 3.0.3 is still beta quality, so unless you tested with Safari 3.0.4
on the Mac, your test result does not account for anything.
I did, in fact, test with Safari 3.0.4.

So, did you go to school to be an arrogant asshole or were you just
born that way?
rynato, meet Thomas, the resident Troll. [further insults]
You really don't know what a troll is
^^^^^^
I am well aware of what a troll is.

Your quoting is well broken. You can't bear the look in the mirror, yes?
And since I know, I won't feed you anymore.

Pot, kettle, black.

ACK.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top