473,383 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Alternative to documentElement.innerHTML?

I am presently making use of documentElement.innerHTML to retrieve
page contents for manipulation, but I've noticed that the sting value
returned is not identical to the actual page source. Specifically,
attribute assignments that look like:

height=100 width=100

in the real source, look like:

height="100" width="100"

in the returned value from documentElement.innerHTML.

Further complicating things, forms that begin insode a table in this
manner:

<table><form ...><tr><td...><input...></form></td>...

Are returned as:

<table><form ...></form><tr><td...><input...

If I modify the returned value from documentElement.innerHTML, then
write it back to documentElement.innerHTML, many of the forms are
non-functional.

I am interested in any available alternatives that will function in
recent Mozilla releases. Thank you,

-Kyle
Jul 20 '05 #1
8 10865
Kyle wrote:
I am presently making use of documentElement.innerHTML to retrieve
page contents for manipulation, but I've noticed that the sting value
returned is not identical to the actual page source. Specifically,
attribute assignments that look like:

height=100 width=100

in the real source, look like:

height="100" width="100"

in the returned value from documentElement.innerHTML.

Further complicating things, forms that begin insode a table in this
manner:

<table><form ...><tr><td...><input...></form></td>...

Are returned as:

<table><form ...></form><tr><td...><input...

If I modify the returned value from documentElement.innerHTML, then
write it back to documentElement.innerHTML, many of the forms are
non-functional.

I am interested in any available alternatives that will function in
recent Mozilla releases. Thank you,


Validate your (X)HTML and you will solve a lot of those problems. Along
with dropping tables for layout.

Read the group FAQ, it discusses how to read a text file (2 methods),
which is what you are trying to do.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #2
Kyle wrote:
I am presently making use of documentElement.innerHTML to retrieve
page contents for manipulation, but I've noticed that the sting value
returned is not identical to the actual page source. Specifically,
attribute assignments that look like:

[...]

Take a look at the DOM specification of W3C. Lots of methods to
manipulate your document.

--
Dirk

(PGP keyID: 0x448BC5DD - http://www.gnupg.org - http://www.pgp.com)

..oO° If I say I love you, will you stay or want to wither, fade away. If
I show you the sun and the night of my past, will a smile cross your
face but just vanish too fast. °Oo.

Jul 20 '05 #3
Kyle skrev, On 1/25/2004 6:51 AM:
I am presently making use of documentElement.innerHTML to retrieve
page contents for manipulation, but I've noticed that the sting value
returned is not identical to the actual page source. Specifically,
attribute assignments that look like:

height=100 width=100

in the real source, look like:

height="100" width="100"

in the returned value from documentElement.innerHTML.

Further complicating things, forms that begin insode a table in this
manner:

<table><form ...><tr><td...><input...></form></td>...

Are returned as:

<table><form ...></form><tr><td...><input...

If I modify the returned value from documentElement.innerHTML, then
write it back to documentElement.innerHTML, many of the forms are
non-functional.

I am interested in any available alternatives that will function in
recent Mozilla releases. Thank you,

-Kyle


The DOM naturally only functions as expected, if the HTML source is as
expected, i.e. is valid due to standards. The examples you give above
are malformed HTML, so the DOM tries to do something about the mishmash.

--
/P.M.

Jul 20 '05 #4
Randy Webb <hi************@aol.com> wrote in message news:<4K********************@comcast.com>...
Kyle wrote:
I am presently making use of documentElement.innerHTML to retrieve
page contents for manipulation, but I've noticed that the sting value
returned is not identical to the actual page source. Specifically,
attribute assignments that look like:

height=100 width=100

in the real source, look like:

height="100" width="100"

in the returned value from documentElement.innerHTML.

Further complicating things, forms that begin insode a table in this
manner:

<table><form ...><tr><td...><input...></form></td>...

Are returned as:

<table><form ...></form><tr><td...><input...

If I modify the returned value from documentElement.innerHTML, then
write it back to documentElement.innerHTML, many of the forms are
non-functional.

I am interested in any available alternatives that will function in
recent Mozilla releases. Thank you,
Validate your (X)HTML and you will solve a lot of those problems. Along
with dropping tables for layout.


This code is resident in a Mozilla extension, not a page that I've
written. It isn't my HTML that I need to parse so I have no control
over it's validity.
Read the group FAQ, it discusses how to read a text file (2 methods),
which is what you are trying to do.


I don't understand what you mean here. As far as I know, the "file"
does not exist anywhere in the filesystem so this is untrue. I assume
this content is somewhere in memory because "View Source" and Sherlock
plugins make use of the real source without accessing the page a 2nd
time.

Thanks for any input.

--Kyle
Jul 20 '05 #5
PeEmm <la*****@ebox.tninet.se> wrote in message news:<bv*********@ripley.netscape.com>...
Kyle skrev, On 1/25/2004 6:51 AM:
I am presently making use of documentElement.innerHTML to retrieve
page contents for manipulation, but I've noticed that the sting value
returned is not identical to the actual page source. Specifically,
attribute assignments that look like:

height=100 width=100

in the real source, look like:

height="100" width="100"

in the returned value from documentElement.innerHTML.

Further complicating things, forms that begin insode a table in this
manner:

<table><form ...><tr><td...><input...></form></td>...

Are returned as:

<table><form ...></form><tr><td...><input...

If I modify the returned value from documentElement.innerHTML, then
write it back to documentElement.innerHTML, many of the forms are
non-functional.

I am interested in any available alternatives that will function in
recent Mozilla releases. Thank you,

-Kyle


The DOM naturally only functions as expected, if the HTML source is as
expected, i.e. is valid due to standards. The examples you give above
are malformed HTML, so the DOM tries to do something about the mishmash.


I should have been more clear. This is a Mozilla Chrome extension, so
I assume that I should have access to the same methods that Mozilla
uses to display the source with "View Source" and retrieve the source
for parsing with Sherlock plugins. Thanks,

--Kyle
Jul 20 '05 #6
Kyle wrote:
Randy Webb <hi************@aol.com> wrote in message news:<4K********************@comcast.com>...
Kyle wrote:
I am interested in any available alternatives that will function in
recent Mozilla releases. Thank you,
Validate your (X)HTML and you will solve a lot of those problems. Along
with dropping tables for layout.

This code is resident in a Mozilla extension, not a page that I've
written. It isn't my HTML that I need to parse so I have no control
over it's validity.


Ok.
Read the group FAQ, it discusses how to read a text file (2 methods),
which is what you are trying to do.

I don't understand what you mean here. As far as I know, the "file"
does not exist anywhere in the filesystem so this is untrue. I assume
this content is somewhere in memory because "View Source" and Sherlock
plugins make use of the real source without accessing the page a 2nd
time.


My response was in direct relation to the assumption (that is now
incorrect) that you were trying to read the HTML code of an HTML file,
and you wanted the original code, not the rendered code (they are
different).

If you load a page, and then do
javascript:alert(document.documentElement.innerHTM L);
In the address bar, and then view the source of the page, on very very
few occasions will they be the same code.

Example:
When I open IE, it opens to about:blank. (actually, all of my browsers
are set to open to about:blank)
View>Source gives this code:
<HTML></HTML>
And thats it.
javascript:alert(document.documentElement.innerHTM L);
alerts this:
<HEAD></HEAD>
<BODY></BODY>

In Mozilla, about:blank view>Source gives this code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><title></title></head>
<body></body>
</html>

I line broke it for readability.

javascript:alert(document.documentElement.innerHTM L);
gives this code:

<head><title></title></head><body></body>

Note the missing DTD and HTML tags.

In order to get the original, written code, of a webpage, into a
variable that the page's javascript can use, you have to read the file
from the server. And the only two ways I know of to do that is with an
HTTPRequestObject or a JAVA applet, hence my suggestion to consult the FAQ.

Whether any of that helps with you trying to read a Mozilla Skin plugin,
I don't know :(
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #7
Randy Webb <hi************@aol.com> writes:
If you load a page, and then do
javascript:alert(document.documentElement.innerHTM L);
In the address bar, and then view the source of the page, on very very
few occasions will they be the same code.
Yes, browsers build the innerHTML structure from the current structure
of the document, whereas the view-source shows the original source code.
That means that innerHTML is "unparsing" the DOM tree structure, and
it would be surpricing if it gave exactly the same formatting as the
original source, even if the structure was the same.

.... In Mozilla, about:blank view>Source gives this code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> ....
javascript:alert(document.documentElement.innerHTM L);
gives this code:

<head><title></title></head><body></body>

Note the missing DTD and HTML tags.


Not surpricing since you ask for the *inner*HTML of the HTML element.
If Mozilla supported the "outerHTML" property, you could also show
the HTML tag. The document type element is even harder to find. It
is the first child of the document element (where the HTML element
is the second).

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #8
Lasse Reichstein Nielsen wrote:
Randy Webb <hi************@aol.com> writes:

If you load a page, and then do
javascript:alert(document.documentElement.innerH TML);
In the address bar, and then view the source of the page, on very very
few occasions will they be the same code.

Yes, browsers build the innerHTML structure from the current structure
of the document, whereas the view-source shows the original source code.
That means that innerHTML is "unparsing" the DOM tree structure, and
it would be surpricing if it gave exactly the same formatting as the
original source, even if the structure was the same.


Formatting aside, even then there are very very few occasions where the
browser will give you what it got. The only way to make them match
(aside from the DTD and HTML tags), is to grab it, paste it into your
editor and then use that code.
....
In Mozilla, about:blank view>Source gives this code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>


....

javascript:alert(document.documentElement.innerH TML);
gives this code:

<head><title></title></head><body></body>

Note the missing DTD and HTML tags.

Not surpricing since you ask for the *inner*HTML of the HTML element.


True. But it only serves to reinforce my statement that if you want the
complete code of the file, you *must* read it from the server, and skip
the parsing. The only two ways I know of to do that is with a java
applet (most widely supported) or with an HTTPRequestObject.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Gernot Frisch | last post by:
Hi, I have found some menu functions. It works quite well, but how can I replace it with a simple <a href> if javascript is turned off? I reduced my code to:...
4
by: RobG | last post by:
I know you aren't supposed to use innerHTML to mess with table structure, but it seems you can't use it just after a table without damaging the containing element. I added a table to a div using...
2
by: petermichaux | last post by:
Hi, I just tested all the browsers I have for support of document.documentElement.scrollLeft to determine how many pixels the window has been scrolled to the right. I'm trying to determine if I...
1
by: raju78.k | last post by:
Hi, I have a problem with FireFox. I have written a function to Add rows without submiting the form. This function works fine in IE, but not in FireFox. The function is : function...
22
by: Dan Rumney | last post by:
Hi all, I've been writing Javascript for quite a while now and have, of late, been writing quite a lot of AJAX and AJAX-related code. In the main, my dynamically generated pages are created...
1
by: shawn aslam | last post by:
My question is leads from the ongoing thread.I am also facing problem of 'innerhtml" when i use IE to see output.If i use FF or Saphire it works well but when i see the output in the HTML it is...
21
by: Aaron Gray | last post by:
(Please tell me if this is silly or I am barking up the wrong tree) Can someone check this please on pre W3C DOM browsers :- function getDocumentRoot() { for ( e in document.childNodes) if (...
1
by: vunet | last post by:
The code below returns the viewport of the browser window but it does not work in IE7 because of the document.documentElement.clientHeight: function pageHeight(){ return window.innerHeight !=...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.