question on Document.prototype modifications 
November 5th, 2005, 12:05 AM
| | | |
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. | 
November 6th, 2005, 05:15 AM
| | | | 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 :-) ) | 
November 6th, 2005, 05:15 AM
| | | | 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 :-) ) | 
November 6th, 2005, 06:35 PM
| | | | 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. | 
November 7th, 2005, 10:15 AM
| | | | 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 |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|