473,770 Members | 6,105 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10908
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.javas cript 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******* *************@c omcast.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.t ninet.se> wrote in message news:<bv******* **@ripley.netsc ape.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******* *************@c omcast.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:aler t(document.docu mentElement.inn erHTML);
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:aler t(document.docu mentElement.inn erHTML);
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:aler t(document.docu mentElement.inn erHTML);
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
HTTPRequestObje ct 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.javas cript FAQ - http://jibbering.com/faq/

Jul 20 '05 #7
Randy Webb <hi************ @aol.com> writes:
If you load a page, and then do
javascript:aler t(document.docu mentElement.inn erHTML);
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:aler t(document.docu mentElement.inn erHTML);
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/rasterTriangleD OM.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:al ert(document.do cumentElement.i nnerHTML);
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:al ert(document.do cumentElement.i nnerHTML);
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 HTTPRequestObje ct.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript 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
2141
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: <script>IncludeMenuHere()</script> More, any tips about "fading" the menu item in and out (x-browser)? Currently it's using DIVs and this.items.visibility(false);
4
6553
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 createElement methods, then added a bit of extra text using innerHTML, only to find most of the attributes removed from the table. Below is a script that calls the same code to add a table inside a div. It adds an onclick to the div and...
2
9494
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 really need to go to all the trouble of feature detection for determine page scroll amount of if the old browsers are old enough now just to ignore them. Below are the OS-browser combinations that worked in my test.
1
15787
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 createRows(deviceId,deviceType,modelName,ipAddress,macAddress,imageURL)
22
2943
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 using Perl on the backend, with Javascript providing limited frontend functionality. As an example, an expanding tree would be fully populated on the server-side and then presented to the browser, with Javascript and CSS being used to vary the...
1
1396
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 not properly aligned.basically i just want to create the row in the existing table and i have achieved this by using innerhtml. but when i c the output is performs the correct functionality but not aligned properly which is very annoyed for our...
21
1930
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 ( document.childNodes.nodeName == "HTML") return document.childNodes; return document.body;
1
10261
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 != null ? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null; }
0
10231
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8887
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7416
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6679
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5452
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.