Connecting Tech Pros Worldwide Forums | Help | Site Map

question on Document.prototype modifications

pierre.bru@gmail.com
Guest
 
Posts: n/a
#1: Nov 5 '05
hello,

I have a page made of a frameset that contains 2 frames.

if in that page I insert a new function in Document.prototype, will
this function be available in the already loaded frames ? if I reload
the frames after using via a <a target="somefame"..>, will the newly
loaded frame have access to the new function ?

TIA,
Pierre.


Joshie Surber
Guest
 
Posts: n/a
#2: Nov 6 '05

re: question on Document.prototype modifications


> will this function be available in the already loaded frames

The frames will have different document.objects from the frameset page,
so the simple answer is no. If you were to say
frames[0].document.prototype then it would apply, but only as long as
the frame was showing the same page. As soon as a new page is loaded a
different document object is created, so you would need to redefine
document.prototype for each page viewed within the frameset.

Unless you are asking if the framed pages could call
top.document.prototypedMethod, in which case yes.

(Sorry for the messy grammer, it is sometimes better :-) )

Joshie Surber
Guest
 
Posts: n/a
#3: Nov 6 '05

re: question on Document.prototype modifications


> will this function be available in the already loaded frames

The frames will have different document.objects from the frameset page,
so the simple answer is no. If you were to say
frames[0].document.prototype then it would apply, but only as long as
the frame was showing the same page. As soon as a new page is loaded a
different document object is created, so you would need to redefine
document.prototype for each page viewed within the frameset.

Unless you are asking if the framed pages could call
top.document.prototypedMethod, in which case yes.

(Sorry for the messy grammer, it is sometimes better :-) )

pierre.bru@gmail.com
Guest
 
Posts: n/a
#4: Nov 6 '05

re: question on Document.prototype modifications


well... I expected Document.prototype to be a template copied into all
new documents created/loaded by the browser, espacially used when a
frame was (re)loaded... :(

thanks for your answer,
Pierre.

aundro
Guest
 
Posts: n/a
#5: Nov 7 '05

re: question on Document.prototype modifications


"Joshie Surber" <joshiesurber@gmail.com> writes:
[color=blue][color=green]
>> will this function be available in the already loaded frames[/color]
>
> The frames will have different document.objects from the frameset page,
> so the simple answer is no. If you were to say
> frames[0].document.prototype then it would apply, but only as long as
> the frame was showing the same page. As soon as a new page is loaded a
> different document object is created, so you would need to redefine
> document.prototype for each page viewed within the frameset.[/color]

I don't think this is quite right.

[Ecma/Java]Script follows the prototype chain, which means if
'document.doSomething()' does not exist (that is: 'doSomething()' is
not a property of 'document'), it will next check into
'document.prototype'.

So, if you have access to the Document type (and it's prototype) in
order to modify it then yes, all your documents should show the
changes.

The following illustrates what I just said (in spidermonkey, just
changed the prompt's '>' to ':' to avoid quoting confusion in newsreaders):


-------------snip------------
aundro@paddy:~$ js
js: function Test () {}
js: var zzz = new Test ();
js: Test.prototype.showStuff = function () {print ("Hy there");}

function () {
print("Hy there");
}

js: zzz.showStuff();
Hy there
js:
aundro@paddy:~$
-------------snip------------


Arnaud

Closed Thread