• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Setting innerHTML decodes encoded characters

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi List,

I have posted a similar question here.
But since it isn't JSP but JavaScript that is killing me I thought I'd ask again in this group. Makes more sense anyways.

Bear already posted some proof that JSP isn't what is bugging me. My tests without AJAX prove he is right.

My AJAX class simply sets the innerHTML of a div to the response of the request. No parsing is done at all.
My response contains encoded HTML characters like "'"...

When the innerHTML is set, the encoded characters are decoded to their literals (tested in IE&FF)...

How can I prevent this?

I have put up a test page that actually shows what happens:
test page
In the box, enter something like: "John's" and click the button...

Thanks in advance,
Rory
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Escape the & to & one more time before you set it to innerHTML.

Eric
 
Rory Slegtenhorst
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eric,

Originally posted by Eric Pascarello:
Escape the & to & one more time before you set it to innerHTML.



I noticed that not EVERY encoded character gets treated in the same manner.
Funnily enough the & isn't being translated to a & grrr... it just keeps the & in the text *sighs*...
And even if IE would support ' it would probably still not do the right thing...
When I enter ' in FF it STILL gets translated into a literal character... this is getting annoying like hell...

Why can't I simply set the innerHTML without it screwing up my code?
The browsers are converting data (when setting innerHTML) before it gets converted again (when it gets rendered)...
It should leave my data alone and let the rendering part take care of the encoded characters...

I am kind of giving up now, cause the problem is getting worse...
And personally I don't think there's going to be an easy way of fixing this. I think I'll just replace the "straight single quote" (&#39 into a "right single quotation mark" (’ or &rsquo
Some people are calling that quotation mark an apostrophe, but let's face it... it isn't... They didn't call it right single quotation mark" for nothing. Last but not least, you try and enter that char from your keyboard (without using alt) hahaha

Thanks again,
Rory
 
Lasagna is spaghetti flvored cake. Just like this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic