Connecting Tech Pros Worldwide Help | Site Map

question on Document.prototype modifications

  #1  
Old November 5th, 2005, 12:05 AM
pierre.bru@gmail.com
Guest
 
Posts: n/a
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.

  #2  
Old November 6th, 2005, 05:15 AM
Joshie Surber
Guest
 
Posts: n/a

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 :-) )

  #3  
Old November 6th, 2005, 05:15 AM
Joshie Surber
Guest
 
Posts: n/a

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 :-) )

  #4  
Old November 6th, 2005, 06:35 PM
pierre.bru@gmail.com
Guest
 
Posts: n/a

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.

  #5  
Old November 7th, 2005, 10:15 AM
aundro
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 14th, 2005 04:15 AM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 11:37 PM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 09:56 PM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 03:15 AM