473,546 Members | 2,244 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HTMLDocument vs. Document when overriding write() ?

I'm writing a library where I want to override document.write( ), but for
all document objects; thus, I want to put it in the prototype. I tried

Document.protot ype.write= my_doc_write ;

but it didn't work. I discovered that this seemed to work:

HTMLDocument.pr ototype.write= my_doc_write ;

Why does HTMLDocument work here but not Document? Will this second
version work reliably across browsers, etc.? Anything to be careful of?

I'm unclear on the relationship between HTMLDocument and Document, which
seems important here. Also, which of the two to use in which situations.
Any explanations of this or appropriate links are welcome.

Thanks!
James
............... ............... ............... ............... ............... ..
James Marshall ja***@jmarshall .com Berkeley, CA @}-'-,--
"Teach people what you know."
............... ............... ............... ............... ............... ..

Jul 20 '05 #1
9 6318
James Marshall <js*@jmarshall. com> writes:
I'm unclear on the relationship between HTMLDocument and Document, which
seems important here. Also, which of the two to use in which situations.
Any explanations of this or appropriate links are welcome.


You are using Mozilla or one of the derivatives. As far as I know,
that is the only browser that implements any of the two. I.e.,
portability is negligable.

On the difference between Document and HTMLDocument, they say:
---
The Document interface that document implements is more general than
HTMLDocument, which derives from it. Document is the interface that
provides such basic hierarchy-manipulating methods and properties as
childNodes, firstChild, nodeType, and others.
---
<URL:http://www.mozilla.org/docs/dom/domref/dom_doc_ref.htm l#1027905>

Since HTMLDocument.pr ototype contains a "write" property, it overrides
any changes you make to Document.protot ype.write.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
"James Marshall" <js*@jmarshall. com> wrote in message
news:Pi******** *************** *************** @jmarshall.com. ..
I'm writing a library where I want to override document.write( ),
but for all document objects; thus, I want to put it in the
prototype. I tried Document.protot ype.write= my_doc_write ;

but it didn't work. I discovered that this seemed to work:

HTMLDocument.pr ototype.write= my_doc_write ;

Why does HTMLDocument work here but not Document?
Without looking at the Mozilla source code (and you are testing on a
gecko based browser) I cannot be certain that I am correct but my guess
would be that Document is the base object for the W3C DOM _Core_
"Document" interface, which does not have a write method, and
HTMLDocument is the base class for the W3C _HTML_ DOM "HTMLDocume nt"
interface, which does have a write method. HTMLDocument extends
Document, adding properties and methods, so modifications to the
Document prototype would be masked by the properties on the HTMLDocument
prototype if they shared the same name. (Document would also be being
used for XML, XSLT, etc documents).
Will this second version work reliably across browsers, etc.?

<snip>

Absolutely not. As far as I know only gecko based browsers currently
expose the W3C interface base classes to JavaScript. And there is
nothing in the ECMA Specifications that requires host objects to be
amenable to modification with JavaScript anyway.

Richard.
Jul 20 '05 #3
On Mon, 20 Oct 2003, Richard Cornford wrote:

RC> "James Marshall" <js*@jmarshall. com> wrote
RC> >I'm writing a library where I want to override document.write( ),
RC> >but for all document objects; thus, I want to put it in the
RC> >prototype. I tried
RC>
RC> > Document.protot ype.write= my_doc_write ;
RC> >
RC> > but it didn't work. I discovered that this seemed to work:
RC> >
RC> > HTMLDocument.pr ototype.write= my_doc_write ;
RC> >
<snip>
RC> >Will this second version work reliably across browsers, etc.?
RC> <snip>
RC>
RC> Absolutely not. As far as I know only gecko based browsers currently
RC> expose the W3C interface base classes to JavaScript. And there is
RC> nothing in the ECMA Specifications that requires host objects to be
RC> amenable to modification with JavaScript anyway.
Thanks Richard and Lasse for the helpful explanations. Yes, you were both
right in that I'm using Mozilla. So now I'm wondering:

If HTMLDocument.pr ototype.write can't be reliably overridden across
browsers, then can Window.prototyp e.open be reliably overridden? (Or is
that what you mean by a "host object"? I'm new to JavaScript.) It works
in Mozilla, and I think I've seen it done in another JS library.

If I can't override the document prototype's write() method, I'm thinking
maybe I can override each individual document's write() method, by first
setting "document.write = my_doc_write", and then in my_window_open( )
setting "newwin.documen t.write= my_doc_write" . Does this seem like a
cross-browser solution? Or do you see a better solution for overriding
all document.write( )'s?
Thanks again,
James
............... ............... ............... ............... ............... ..
James Marshall ja***@jmarshall .com Berkeley, CA @}-'-,--
"Teach people what you know."
............... ............... ............... ............... ............... ..

Jul 20 '05 #4
James Marshall wrote:
On Mon, 20 Oct 2003, Richard Cornford wrote:
RC> "James Marshall" <js*@jmarshall. com> wrote ^^^
Please don't use initials in your quotes as it is confusing newsreaders
which assume `>' to be the identificator of a quote (and therefore color
them different). The thread and the attribution lines are enough to
recognize who wrote what. I have cut them out here for the sake of an
easily readable posting.
[...] As far as I know only gecko based browsers currently
expose the W3C interface base classes to JavaScript. And there is
nothing in the ECMA Specifications that requires host objects to be
amenable to modification with JavaScript anyway.


[...]
If HTMLDocument.pr ototype.write can't be reliably overridden across
browsers, then can Window.prototyp e.open be reliably overridden?


Overridden -- yes. Reliably -- no.
(Or is that what you mean by a "host object"? I'm new to JavaScript.)
From JavaScript 1.5 on, `window' is not longer part of the core language but
a host object which is part of the DOM of the UA (that means essentially
that it is now officially browser-dependent.)
It works in Mozilla,
Because the Gecko DOM supports that.
and I think I've seen it done in another JS library.
What's your point?
If I can't override the document prototype's write() method, I'm thinking
maybe I can override each individual document's write() method, by first
setting "document.write = my_doc_write", and then in my_window_open( )
setting "newwin.documen t.write= my_doc_write" . Does this seem like a
cross-browser solution?
No, not at all, since the conventions for the `window' object also apply
to the `document' object, which in fact became(?) a property of `window'.
Or do you see a better solution for overriding all document.write( )'s?
Maybe. Could you please explain what you are exactly trying to achieve?
............... ............... ............... ............... ............... ..
James Marshall ja***@jmarshall .com Berkeley, CA @}-'-,--
"Teach people what you know."
............... ............... ............... ............... ............... ..


A signature is to be separated by `-- ' (dashDashSpace)
which makes it being automagically removed from replies
and colored different/hidden (if supported.)
PointedEars

Jul 20 '05 #5
In article <3F************ **@PointedEars. de>, Thomas 'PointedEars' Lahn
<Po*********@we b.de> writes:

PointedEars>
PointedEars>Jam es Marshall wrote:
PointedEars>
PointedEars>> On Mon, 20 Oct 2003, Richard Cornford wrote:
PointedEars>> RC> "James Marshall" <js*@jmarshall. com> wrote
PointedEars> ^^^
PointedEars>Ple ase don't use initials in your quotes as it is confusing
newsreaders
PointedEars>whi ch assume `>' to be the identificator of a quote (and therefore
color
PointedEars>the m different). The thread and the attribution lines are enough to
PointedEars>rec ognize who wrote what. I have cut them out here for the sake of
an
PointedEars>eas ily readable posting.

Is this comp.lang.javas cript or is it alt.how.to.post ? You seem to comment on
every post that you reply to about the quoting methods of anybody you reply to.
Its getting rather obnoxiously old.

But since you are complaining about his quoting style (the RC in the quote),
please refrain from assuming that all newsreaders will space the same way yours
does. In mine, your ^^^^ points at the >, not the RC that you are complaining
about.

Since I did not use initials, then your newsreader shouldn't have problems with
my quoting scheme. Its not the initials causing the problem but the fact that
there are characters prior to the > in the quote.

P.S. You also forgot to tell him to trim the header line (is that what its
called?) and no, I won't change my way of quoting to accomodate your
newsreader, just as I won't ask you to change your way to accomodate mine.
--
Randy
Jul 20 '05 #6
"James Marshall" <js*@jmarshall. com> wrote in message
news:Pi******** *************** *************** @jmarshall.com. ..
<snip>
If HTMLDocument.pr ototype.write can't be reliably overridden
across browsers, then can Window.prototyp e.open be reliably
overridden?
Not window.prototyp e.open because most browsers do not expose a
prototype for the window object, but window.open can be replaced with
another function directly (at least in all of the HTML browsers that I
can think of). In fact that is how content inserting/re-writing proxys
often implement their pop-up blocking abilities.
(Or is that what you mean by a "host object"? I'm new to
JavaScript.) It works in Mozilla, and I think I've seen
it done in another JS library.
I mentioned ECMA Script's attitude towards host objects mostly to point
out that while in reality DOM objects are usually quite happy to be
modified with scripts there is no standard requiring them to. So when
(or if) you encounter and environment that does not allow it you have no
grounds for complaint, as the fault is the script author's for assuming
that it would be allowed rather than the browser author's for failing to
comply with some standard.

JS libraries are an interesting phenomenon. There was a time when I
thought that they were a good idea, allowing a single and consistent
interface to the very varied environments of web browsers. As I have
learnt more about browser scripting I have come to see that they are
generally a very bad idea. Apart from often requiring the download of a
fairly large chunk of JS code (of which only a tiny fraction may be
needed for the page in question) and preventing the JS author from
getting to grips with the problems of cross-browser scripting for
themselves, they are usually written with an optimistic attitude towards
their own success. That is, the author knows enough to put a consistent
API on all of the browsers that he/she was aware of but rarely do those
libraries make prevision for handling their own failure in the face of
the unknown. And without the ability to fail under control, clean
degradation becomes difficult.
If I can't override the document prototype's write() method,
I'm thinking maybe I can override each individual document's
write() method, by first setting "document.write = my_doc_write",
You probably can, but what would be the point in overriding the write
method on your own pages (and don't forget writeln)? If you have an
alternative method then you can just call that instead of
document.write.
and then in my_window_open( ) setting
"newwin.docume nt.write= my_doc_write" .
That is unlikely to work. JavaScript functions are objects so
my_doc_write is an object in the current window (it occupies memory
their), the chances of more than a couple of browsers letting you
execute a function from a different window as a method in their window
is not high (framesets might be a different story), but even if it works
as soon as the opener window is navigated or closed my_doc_write is
gone.

You might have slightly more success if you create a "copy" of your
function in the new window by providing a function body string to that
window's Function constructor:-

newwin.document .write = new newwin.Function ( sFunctionBody );

But attempting that in a replacement window.open function will almost
certainly suffer from timing problems as window.open is asynchronous and
while it returns a reference to a window object there is not guarantee
at the point that it returns that the new window object contains a
document object at all.
Does this seem like a cross-browser solution?
I would start to judge any proposed solution by identifying the problem
it was intended to solve. Unfortunately, I don't actually know what the
problem this is intended to solve is.
Or do you see a better solution for overriding
all document.write( )'s?


First establish whether the problem necessitates the overriding of
document.write, then worry about what would be the best way to implement
that.

Richard.
Jul 20 '05 #7
HikksNotAtHome wrote:
[...]
Is this comp.lang.javas cript or is it alt.how.to.post ? You seem to comment on
every post that you reply to about the quoting methods of anybody you reply to.
Its getting rather obnoxiously old.
In contrast to your posting, mine was at least on-topic for
the most part. Grab your own nose.

And if you don't want to post so that your postings are for
your readers, why the hell are you posting in the first place?
PointedEars>
PointedEars>Jam es Marshall wrote:
[aso.]


If it was not obvious that names/initials in every line
of quote destroys readability, it should be obvious now.
PointedEars

Jul 20 '05 #8
"Richard Cornford" <Ri*****@litote s.demon.co.uk> wrote in message
news:bn******** **********@news .demon.co.uk...
<snip>
... , but window.open can be replaced with another function
directly (at least in all of the HTML browsers that I
can think of). ...

<snip>

I obviously wasn't thinking that clearly when I wrote that as there are
no shortage of small PDA and embedded HTML browsers that do not have a
window.open function to start with, and you cannot replace what doesn't
exist.

Richard.
Jul 20 '05 #9
"Thomas 'PointedEars' Lahn" <Po*********@we b.de> wrote in message
news:3F******** ******@PointedE ars.de...
[...]
Is this comp.lang.javas cript or is it alt.how.to.post ? You
seem to comment on every post that you reply to about the
quoting methods of anybody you reply to. Its getting rather
obnoxiously old.


In contrast to your posting, mine was at least on-topic for
the most part. Grab your own nose.

And if you don't want to post so that your postings are for
your readers, why the hell are you posting in the first place?
PointedEars >
PointedEars>J ames Marshall wrote:
[aso.]


If it was not obvious that names/initials in every line
of quote destroys readability, it should be obvious now.


Ultimately the acceptable posting style for the group is outlined in the
FAQ (section 2.3) and the resources that it references. And given that
the FAQ does prescribe a posting style for this group it seems
inappropriate to be proposing a more restrictive style to users of the
group, especially when some of those restrictions appear to be based on
nothing other than your personal opinion and perceptions.

You are of course free to lobby for modifications to section 2.3 (as per
section 5.2) to bring it into line with your particular interpretation
of an appropriate style for Usenet postings, and I am sure that if your
proposed changes met with a consensus of approval (or even a majority of
expressed opinions) Jim would happily modify the FAQ accordingly.

Richard.
Jul 20 '05 #10

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

Similar topics

14
4089
by: Eli | last post by:
I've got a script that I'm trying to debug which uses document.write() to place HTML within a page. In both IE6 and Firefox when I view source, I see only the script itself and not any HTML as it's being written into the page. Is there a way that I can view what is being placed into the page, instead of, or in addition to the javascript...
2
14931
by: John Mack | last post by:
Intermittently I get the following error on Firefox: "Error: uncaught exception: Permission denied to get property HTMLDocument.window" What can cause this error? I do an image switch via JS just before redirecting the page (also via JS), could this be the problem - not giving enough time to do the image switch before redirecting? ...
0
1951
by: Filippo Bettinaglio | last post by:
VS2005, C# I have developed a UserControl embedded in a HTML web page. And I can access to the DOM with the following code: HTML page: …….. <BODY onload=loadDoc()> …….
2
14788
by: Paul Hemans | last post by:
I am very new at .Net. I have a small project where I need to manipulate the contents of a web page. I have a form with a web browser control (webBrowser1) on it. Within the webBrowser1_DocumentCompleted method I have the following code. mshtml.HTMLDocument oDoc = new HTMLDocumentClass(); oDoc = (mshtml.HTMLDocument)webBrowser1.Document;
9
4073
by: Le Minh | last post by:
Hi, i want to write a program. Input of this is HTML source code of a web page and output is a treeview representation it structure. I want to write it with HtmlDocument in .net framework 2.0. how i write it?
5
3185
by: Jeff | last post by:
Is there a standard way of getting the HTMLDocument object representation of a remote page using Javascript? If I request an HTML page, the xmlHttpRequest returns either text or an XMLDocument. I can't figure out how to convert the former into an HTMLDocument object and the latter doesn't seem to work if the page isn't valid XHTML. If...
0
1867
by: nickin4u | last post by:
I have a application that is used to automate certain task, I have been using mshtml.HTMLDocument class but certain events like click a button do not fire. I have tried a number of combinations but in vain. I was now trying to use System.Windows.Forms.Htmldocument class; here is the code Dim do1 As System.Windows.Forms.HtmlDocument =...
2
3981
by: CSharper | last post by:
Is there a class I can use which loads HtmlDocument and performs default html validation to see if the document is a valid html document like XDocument? HtmlDocument seems to me only used to create HtmlDocument and there are no methods to load the existing HTML document. Thanks,
1
1840
by: orensol | last post by:
Hello, I am trying to override document.write, because there are cases in which a slow response from a <script src=...request which produces document.write calls is received after the page has finished loading. In that case, it overwrites the entire page (as document.write does when the page parsing is over). I am trying to use Resig's...
0
7507
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7698
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. ...
0
7794
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6030
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...
1
5361
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...
0
5080
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...
0
3492
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...
0
3472
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1046
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.