HighDots Forums  

Problem dealing with double quotes in InnerHTML

Javascript JavaScript language (comp.lang.javascript)


Discuss Problem dealing with double quotes in InnerHTML in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
rf
 
Posts: n/a

Default Re: Problem dealing with double quotes in InnerHTML - 12-11-2007 , 05:08 AM







"Mahernoz" <mahernoz (AT) gmail (DOT) com> wrote

Quote:
On Dec 11, 3:36 pm, "rf" <r... (AT) invalid (DOT) com> wrote:
"Mahernoz" <maher... (AT) gmail (DOT) com> wrote in message


In any case consider &quote;

--
Richard.

I am stuck up here with a bug in IE6.

to simplify i have made a demo program.

p onclick="alert(this.innerHTML);"><font class="AInput">3434</font></
p

it surprisingly removes the double quotes in IE6.

I need that when onclick is fired i should also get double quotes.
which means...
i need <font class="AInput">3434</font> output
instead of
font class=AInput>3434</font> as output.
Sorry but I still have no idea what your are talking about nor what your
quote issue is. You keep saying quotes are removed but you still fail to
state from where.

Enough for me :-)

--
Richard.




Reply With Quote
  #12  
Old   
Mahernoz
 
Posts: n/a

Default Re: Problem dealing with double quotes in InnerHTML - 12-11-2007 , 05:21 AM






On Dec 11, 3:53 pm, RobG <rg... (AT) iinet (DOT) net.au> wrote:
Quote:
On Dec 11, 8:27 pm, Mahernoz <maher... (AT) gmail (DOT) com> wrote:



On Dec 11, 2:54 pm, RobG <rg... (AT) iinet (DOT) net.au> wrote:
[...]
Given:

p onclick="alert(this.innerHTML);">get "innerHTML"</p

IE 6 shows:

get "innerHTML"

so your issue is not with the innerHTML property itself.
[...]
if i replace that string with this string then there are no double
quotes...

p onclick="alert(this.innerHTML);"><font class="AInput">3434</font></
p

it surprisingly removes the double quotes.

Quotes around attribute values are not mandatory in HTML, they are
only required where the value has certain characters:

"In certain cases, authors may specify the value of an attribute
without any quotation marks. The attribute value may only
contain letters (a-z and A-Z), digits (0-9), hyphens (ASCII
decimal 45), periods (ASCII decimal 46), underscores (ASCII
decimal 95), and colons (ASCII decimal 58). We recommend using
quotation marks even when it is possible to eliminate them."

URL:http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2

I guess whoever implemented innerHTML in IE decided to remove them
where they aren't required.

As David said, there is no public standard for innerHTML and what
there is at MSDN is scant - it does not say that it returns exactly
the original source. So you are left to parse the value yourself and
insert quotes as appropriate. You should also convert attribute names
to lower case, as some browsers will report them in uppercase.

I think the whole idea of using innerHTML as the source of valid XML
markup is flawed.

--
Rob

Hi,

I think the whole idea of using innerHTML as the source of valid XML
markup is flawed.
- Can you recommend a method which is a "better way" to take the html-
contents of a DIV from an html file and put it into a database. (this
html will be rendered on a page, so i need to make it well-formed.)

I don't want implementation details, just a suggestion of having a
better way.

Regards,
Mahernoz



Reply With Quote
  #13  
Old   
David Mark
 
Posts: n/a

Default Re: Problem dealing with double quotes in InnerHTML - 12-11-2007 , 05:28 AM



On Dec 11, 6:21 am, Mahernoz <maher... (AT) gmail (DOT) com> wrote:
Quote:
On Dec 11, 3:53 pm, RobG <rg... (AT) iinet (DOT) net.au> wrote:



On Dec 11, 8:27 pm, Mahernoz <maher... (AT) gmail (DOT) com> wrote:

On Dec 11, 2:54 pm, RobG <rg... (AT) iinet (DOT) net.au> wrote:
[...]
Given:

p onclick="alert(this.innerHTML);">get "innerHTML"</p

IE 6 shows:

get "innerHTML"

so your issue is not with the innerHTML property itself.
[...]
if i replace that string with this string then there are no double
quotes...

p onclick="alert(this.innerHTML);"><font class="AInput">3434</font></
p

it surprisingly removes the double quotes.

Quotes around attribute values are not mandatory in HTML, they are
only required where the value has certain characters:

"In certain cases, authors may specify the value of an attribute
without any quotation marks. The attribute value may only
contain letters (a-z and A-Z), digits (0-9), hyphens (ASCII
decimal 45), periods (ASCII decimal 46), underscores (ASCII
decimal 95), and colons (ASCII decimal 58). We recommend using
quotation marks even when it is possible to eliminate them."

URL:http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2

I guess whoever implemented innerHTML in IE decided to remove them
where they aren't required.

As David said, there is no public standard for innerHTML and what
there is at MSDN is scant - it does not say that it returns exactly
the original source. So you are left to parse the value yourself and
insert quotes as appropriate. You should also convert attribute names
to lower case, as some browsers will report them in uppercase.

I think the whole idea of using innerHTML as the source of valid XML
markup is flawed.

--
Rob

Hi,

I think the whole idea of using innerHTML as the source of valid XML
markup is flawed.
- Can you recommend a method which is a "better way" to take the html-
contents of a DIV from an html file and put it into a database. (this
html will be rendered on a page, so i need to make it well-formed.)
It certainly doesn't have to be well-formed to render on a page,
unless you are serving it as XHTML (which is impossible in IE.)

An innerHTML wrapper is fairly simple to write, but you will need to
write a getAttribute wrapper first as IE's implementation of that
method (which is a standard) is botched. Just iterate through the
child nodes of the element, recursing for each element node and build
the (X)HTML string.


Reply With Quote
  #14  
Old   
Randy Webb
 
Posts: n/a

Default Re: Problem dealing with double quotes in InnerHTML - 12-11-2007 , 08:12 AM



Mahernoz said the following on 12/11/2007 5:42 AM:

<snip>

Quote:
I am stuck up here with a bug in IE6.
No, there is no "bug" in IE6 with regards to what you are seeing.

Quote:
to simplify i have made a demo program.

p onclick="alert(this.innerHTML);"><font class="AInput">3434</font></
p

it surprisingly removes the double quotes in IE6.
It removes quotes that aren't required. Want it to leave the quotes? Add
a trailing space. Won't make a hill of beans to HTML but it will cause
IE to leave the optional quote marks.

<p onclick="alert(this.innerHTML);"><font class="AInput ">3434</font></
p>

Note the space after the class name.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Reply With Quote
  #15  
Old   
Evertjan.
 
Posts: n/a

Default Re: Problem dealing with double quotes in InnerHTML - 12-11-2007 , 08:52 AM



Randy Webb wrote on 11 dec 2007 in comp.lang.javascript:

Quote:
Mahernoz said the following on 12/11/2007 5:42 AM:

snip

I am stuck up here with a bug in IE6.

No, there is no "bug" in IE6 with regards to what you are seeing.

to simplify i have made a demo program.

p onclick="alert(this.innerHTML);"><font
class="AInput">3434</font></ p

it surprisingly removes the double quotes in IE6.

It removes quotes that aren't required. Want it to leave the quotes?
Add a trailing space. Won't make a hill of beans to HTML but it will
cause IE to leave the optional quote marks.

p onclick="alert(this.innerHTML);"><font class="AInput
">3434</font></
p

Note the space after the class name.
It seems some of us expect innerHTML to return
the HTML script from the html file
that rendered the browser page.

This is not the case!!

innerHTML just returns the string version
of the rendered html in the browser.

One could say that the string is build anew
from the requested element's inner DOM tree.


Example file [IE7]:

<table onclick='alert(this.innerHTML)'>
<tr><td>Blah</tr></td>
<table>

alerts thus:

<TABLE>
<TBODY>
<TR>
<TD>Blah </TD></TR></TBODY></TABLE>

And this file [IE7]:

<div onclick='alert(this.innerHTML)'>
<table>
<tr><td>
Blah
</table>
</div>

alerts EXACTLY the same RENDERED code
as the first file example did!!!!

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Reply With Quote
  #16  
Old   
Evertjan.
 
Posts: n/a

Default Re: Problem dealing with double quotes in InnerHTML - 12-11-2007 , 08:56 AM



Evertjan. wrote on 11 dec 2007 in comp.lang.javascript:

Quote:
One could say that the string is build anew
from the requested element's inner DOM tree.


Example file [IE7]:

table onclick='alert(this.innerHTML)'
tr><td>Blah</tr></td
table

Sorry, I ment this one :

<div onclick='alert(this.innerHTML)'>
<table>
<tr><td>
Blah
</td></tr>
</table>
</div>



Quote:
alerts thus:

TABLE
TBODY
TR
TD>Blah </TD></TR></TBODY></TABLE

And this file [IE7]:

div onclick='alert(this.innerHTML)'
table
tr><td
Blah
/table
/div

alerts EXACTLY the same RENDERED code
as the first file example did!!!!



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Reply With Quote
  #17  
Old   
Randy Webb
 
Posts: n/a

Default Re: Problem dealing with double quotes in InnerHTML - 12-11-2007 , 09:03 AM



Evertjan. said the following on 12/11/2007 9:52 AM:
Quote:
Randy Webb wrote on 11 dec 2007 in comp.lang.javascript:

Mahernoz said the following on 12/11/2007 5:42 AM:

snip

I am stuck up here with a bug in IE6.
No, there is no "bug" in IE6 with regards to what you are seeing.

to simplify i have made a demo program.

p onclick="alert(this.innerHTML);"><font
class="AInput">3434</font></ p

it surprisingly removes the double quotes in IE6.
It removes quotes that aren't required. Want it to leave the quotes?
Add a trailing space. Won't make a hill of beans to HTML but it will
cause IE to leave the optional quote marks.

p onclick="alert(this.innerHTML);"><font class="AInput
">3434</font></
p

Note the space after the class name.

It seems some of us expect innerHTML to return
the HTML script from the html file
that rendered the browser page.

<div id="someContainer">old content</div>
document.getElementById('someContainer').innerHTML ="new content";
alert(document.getElementById('someContainer').inn erHTML);

Should the alert give you "old content" or "new content"?

Quote:
This is not the case!!

innerHTML just returns the string version
of the rendered html in the browser.
It returns the normalized HTML that the browser is using.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Reply With Quote
  #18  
Old   
Evertjan.
 
Posts: n/a

Default Re: Problem dealing with double quotes in InnerHTML - 12-11-2007 , 10:13 AM



Randy Webb wrote on 11 dec 2007 in comp.lang.javascript:

Quote:
It seems some of us expect innerHTML to return
the HTML script from the html file
that rendered the browser page.


div id="someContainer">old content</div
document.getElementById('someContainer').innerHTML ="new content";
alert(document.getElementById('someContainer').inn erHTML);

Should the alert give you "old content" or "new content"?
In IE7 I get "new content", as expected.

Expected, because that is
the textNode reconstructed into a Javascript string,
and then alerted out.

"Should" however is what the specs say. [If they do]

Quote:
This is not the case!!

innerHTML just returns the string version
of the rendered html in the browser.

It returns the normalized HTML that the browser is using.
I do not think the browser is "using" a normalized HTML sting.

The browser just renders the DOM from the html file text as it is.

What the browser reconstructs from the DOM to a string for use in
innerHTML, would you call that "normalized"?

I don't think so, as a possible error made here in that reconstruction
does not harm the DOM if the innerHTML string is not used for changing
the DOM.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Reply With Quote
  #19  
Old   
Randy Webb
 
Posts: n/a

Default Re: Problem dealing with double quotes in InnerHTML - 12-11-2007 , 11:20 AM



Evertjan. said the following on 12/11/2007 11:13 AM:
Quote:
Randy Webb wrote on 11 dec 2007 in comp.lang.javascript:

It seems some of us expect innerHTML to return
the HTML script from the html file
that rendered the browser page.

div id="someContainer">old content</div
document.getElementById('someContainer').innerHTML ="new content";
alert(document.getElementById('someContainer').inn erHTML);

Should the alert give you "old content" or "new content"?

In IE7 I get "new content", as expected.
But, that isn't the "HTML script from the html file". I was showing a
simple example of where you *wouldn't* want the code from the HTML file.

Quote:
Expected, because that is the textNode reconstructed into a Javascript
string, and then alerted out.
<URL: http://msdn2.microsoft.com/en-us/library/ms533897.aspx>
<quote>
Sets or retrieves the HTML between the start and end tags of the object.
</quote>

Quote:
"Should" however is what the specs say. [If they do]
Doesn't say one way or the other, other than what I quoted.
</quote>
Standards Information

There is no public standard that applies to this property.
</quote>

I guess it means MS can do what they want since they invented it and you
can't tell them they implemented something they invented incorrectly.

Quote:
This is not the case!!

innerHTML just returns the string version
of the rendered html in the browser.
It returns the normalized HTML that the browser is using.

I do not think the browser is "using" a normalized HTML sting.
What MSDN refers to it as is "sanitized HTML". Not sure I would call
what IE does with it "sanitized" though.

Quote:
The browser just renders the DOM from the html file text as it is.

What the browser reconstructs from the DOM to a string for use in
innerHTML, would you call that "normalized"?
I think that is about what it is. I think the first time I ever read
about "normalized" was from Jim Ley and it is just what stuck with me.
The internal representation of HTML code.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Reply With Quote
  #20  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: Problem dealing with double quotes in InnerHTML - 12-12-2007 , 02:57 PM



RobG wrote:
Quote:
On Dec 11, 5:10 pm, Mahernoz <maher... (AT) gmail (DOT) com> wrote:
I have some problem here. I am using Asp.net 2.0 but that is not
^^^^^^^^^^^^^^^^^^^^^^
relevant to my Question.

I have a <div> tag.
div id="dvAArea" runat="server"></div

Div elements don't have a runat attribute in HTML 4.
True, however I suppose it only looks like HTML. Which would mean the
OP is wrong as their runtime environment is relevant to their question.


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.