473,407 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

question on Document.prototype modifications

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.

Nov 5 '05 #1
4 3626
> 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 :-) )

Nov 6 '05 #2
> 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 :-) )

Nov 6 '05 #3
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.

Nov 6 '05 #4
"Joshie Surber" <jo**********@gmail.com> writes:
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.


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

Nov 7 '05 #5

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

Similar topics

2
by: Bob | last post by:
This seems to me like it should work but I get "generic" no matter which button I click. Javascript is not one of my better languages. Can the experts here take a look at this and tell me what I'm...
9
by: James Marshall | last post by:
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.prototype.write= my_doc_write ; but it...
15
by: Alex | last post by:
could somebody tell me the difference between those two styles: function abc(var1, var2){ /* logic in here */ } and abc = function(var1, var2){ /* logic in here */ }; When / why would I...
10
by: b.dam | last post by:
I'm trying the following: function grid() { this._el = document.createElement("TABLE"); var self = this; document.addEventListener("onkeydown", function(event) {self.gridKeyDown(event);},...
14
by: petermichaux | last post by:
Hi, Hopefully the group doesn't mind an(other) inheritance question. Maybe the prototype inheritance style is starting to become a low dim light in my brain...probably not yet. ---- If I...
7
by: bayfaulkscatering | last post by:
I'm definitely not new to JS, but for the life of me, I can't figure this one out. Here's basically what I'm doing: function foo() { alert(this); } span = document.createElement('span'); a...
5
by: Daz | last post by:
Hi everyone. My query is very straight forward (I think). What's the difference between someFunc.blah = function(){ ; } and
2
by: King Albert | last post by:
Question : Is it 'good design' to make an eventhandler a method of your class ? Problem in the eventhandler below : I need 'this' to refer to Tabel, not to the clicked element ! ...
29
by: Nick | last post by:
I've seen a few frameworks use the following: function $(id) { return document.getElementById(id); } Then to use: $('something').innerHTML = 'blah'; I'm just trying to roll this out to my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.