SiteExperts.com Logo Home | Community | Developer's Paradise
User Groups | Site Tools | Site Information | Search
 Main Menu
 Forums
SiteExperts.com Forums
All Discussions

SiteExperts Feedback
The Lounge
Dynamic HTML
Site Design/ Critiques
HTML and CSS
XML Technologies
The Wireless Internet
Internet Explorer
Microsoft .NET
The Server
Technical Support

Sponsored Links

User Groups : Forums : SiteExperts : HTML and CSS :

Previous DiscussionNext Discussion
 read the actual html using innerhtml, etc?

My rich editor is changing my HTML and it's annoying me.

I have a node in my DOM that contains the code of a unicode equivalent character represented as html, such as Ω which is an ampersand followed by a capital O followed by the string 'mega' followed by a semicolon.

If I read the value using node.innerHTML, or node.firstChild.nodeValue then in IE I get the actual rendered character code. I want to be able to read the html of the page, so that rather than seeing the Ω character i want to see the code that makes up that character.

My only other option is to put in a process during the save process that says replace Ω with the sequence & O m e g a ; and then save those bytes out.

What is the correct way to read the "actual value" of the node, not "what is shown on the screen" ?

Started By frumbert on Jul 14, 2010 at 5:49:17 PM

6 Response(s) | Reply

Earlier Replies | Replies 2 to 6 of 6 | Later Replies
jalarie on Jul 15, 2010 at 1:12:33 PM (# 2)
This message has been edited.

Use the JavaScript "Data=window.document.body.innerHTML;" to read the data.

The Greek codes run from 913 through 937 for the upper-case alpha through omega and from 945 through 969 for the lower-case. Put an and sign (&) and pound sign (#) ahead of the code number and a semicolon (;) after it.


frumbert on Jul 15, 2010 at 4:12:56 PM (# 3)
This message has been edited.

actually this does not work. Consider the following example.
When you press the button you get an alert that shows the original string that was set as the value in the p, and what you get when it reads the same value back using innerHTML. They are not the same thing.
<html>
<head>
<script type="text/javascript">
function doIt() {
var s = "The quick brown &#969; is &copy; copyright 2010";
var el1 = document.getElementById("my_p");
var el2 = document.getElementById("my_other_p");
el1.innerHTML = s;
el2.appendChild(document.createTextNode(s));

var read1 = el1.innerHTML;
var read2 = el2.innerHTML;

alert("Original value:\n"+s+"\nInner HTML1:\n"+read1+"\nInner HTML2:\n"+read2);
}
</script>
</head>
<body>
<h1>First value</h1>
<p id="my_p"></p>
<h1>Second value</h1>
<p id="my_other_p"></p>
<input type="button" value="go" onclick="doIt()" />
</body>
</html>


Terry Young on Jul 21, 2010 at 10:18:39 AM (# 4)
This message has been edited.

The line with createTextNode is flawed.

createTextNode creates text, not HTML

Your "s" variable is essentially an HTML string, not a text string.

Here:

document.createTextNode("The quick brown " + String.fromCharCode(969) + " is " + String.fromCharCode(169) + " copyright 2010")

Still thinking about the original question though...


Terry Young on Jul 21, 2010 at 10:43:01 AM (# 5)
This message has been edited.

Stumbled upon this:

http://www.dave-smith.info/character-entity-reference-converter-using-javascript.html

Copy this rendered "The quick brown ω is © copyright 2010" into the textarea and click "Convert".

Looks like an exhaustive approach.

Not yet sure if this is the only solution, but I believe it is.


MHenke on Jul 23, 2010 at 2:51:13 AM (# 6)
This message has been edited.

It's not that I've to say something substantial WRT the original question.
But, as always, I don't care a pap.
I just want to say how gratifying it is to see an actual discussion on SE.
As much as such renowned members are involved (e.g. mhenke). ;)


Earlier Replies | Replies 2 to 6 of 6 | Later Replies

To respond to a discussion, you must first logon.

If you are not registered, please register yourself to become a member of the SiteExperts.community.

User Name
Password
Copyright 1997-2004 InsideDHTML.com, LLC. All rights reserved.