473,847 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Frame handling

I'm looking for tutorials or articles considering HTML Frames and how to
handle them with Javascript.

E.g. samples how Frames can exchange information, can a Frame instruct
other Frame to update it's content etc.

This kind of information is welcome.

Cheers!

Jul 23 '05 #1
5 4462
Frame wrote:
I'm looking for tutorials or articles considering HTML
Frames and how to handle them with Javascript.

E.g. samples how Frames can exchange information, can a
Frame instruct other Frame to update it's content etc.

This kind of information is welcome.


First off, be very certain that you need to be using frames at all. They
introduce a lot of issues that do not exist in single web pages, some of
which are significant to scripting such structures.

For single web page the scripting environment has a single global
object, and that global object is the 'window' object. An object that
can be referred to by the identifiers - window - and - self - (and,
because there is no frameset hierarchy, by the identifiers - parent -
and - top -, and from code executing in the global context, or from
within function not being executed as methods of objects, with the -
this - keyword).

In a frameset each page (including any pages defining a frameset) has
its own global object, which is also a 'window' object (though it would
be better referred to as a 'frame' object in that context). Thus code
executing within any page in the frameset can refer to its own
global/window/frame object using the unqualified identifiers - window -
and - self -. However, these global/window/frame objects form a
tree-like hierarchy in a frameset. The unqualified identifier - top -
refers to the top-most (or root) global/window/frame object in that
hierarchy from any frame. And the identifier - parent - refers to the
global/window/frame object that directly contains the
global/window/frame object from which the reference is made (The one
which has loaded the html page that includes the FRAME element that
loaded the page using the - parent - reference).

Global variables and function definitions become named properties of the
global object that contains the document in which they are defined (or
which imports the script files in which they are defined). This means
that if a (top-most) frameset page defines a function called -
doSomething - then code imported into one of the pages within that
frameset can call that function as:-

top.toSomething (x, y);

Similarly, if the top-most frameset page has a global variable call -
something - then a page within the frameset could, for example, assign a
value to that variable as:-

top.something = 42;

A page that is a direct child of the top-most frameset page could use:-

parent.toSometh ing(x, y);

- and -

parent.somethin g = 42;

and if the top-most frameset page defines a frame that itself loaded a
frameset a page within that contained frameset could use:-

parent.parent.t oSomething(x, y);

- and -

parent.parent.s omething = 42;

Referencing the global/window/frame objects from parent to child is done
through the - frames - collection, which has an indexed member for each
frame (including IFRAME) directly contained within a frameset page. The
members of the - frames - collection can also be referenced by name,
that is, the - frames - collection has a named member, the name of which
corresponds with the NAME attribute of the defined FRAME element. More
recent browsers also support named references within the -
frames -collection using names that correspond with the ID attribute of
FRAME elements, but to maximise support it is probably advisable to give
FRAME elements both NAME and ID attributes that have identical values
(assuming the pertinent DTD allows that, as they probably will as strict
DTDs don't accommodate FRAME elements anyway).

So a frameset page that defines a FRAME element as:-

<frame src="http://exampele.com/page.html" name="main" id="main">

- can reference the global/window/frame object that contains -
page.html - using:-

frames['main']

and if that frameset specified a second frame:-

<frame src="http://exampele.com/page2.html" name="menu" id=" menu ">

- then code within that second frame can refer to its sibling (main)
as:-

parent.frames['main']

It is important to note that the - frames - collection only contains
references to the global/window/frame objects that are direct children
of the global/window/frame object that possesses the particular -
frames - collection. Frames that are children of those contained frames
need to be referenced through their parent's - frames - collection. So,
in the above example, if - main - was itself a frameset that defined
FRAME elements with the names/IDs "mainLeft" and "mainRight" then code
in the top-most frameset page would refer to one of those two frames
as:-

frames['main'].frames['mainLeft']

(Though probably a bit more cautiously than that as there would be no
guarantee that main had loaded its HTML and so its - frames - collection
may be empty at the time when the property accessor was evaluated.)

Given that the global/window/frame objects that correspond with all of
the windows/frames defined in a frameset (or nested framesets) form a
tree-like hierarchy they can all be referenced from any locution in that
structure using appropriate combinations of - parent -, - top -, and -
frames - in the property accessors.

Richard.
Jul 23 '05 #2

"Frame" <fr***@mail.n o> schreef in bericht
news:38******** *****@individua l.net...
I'm looking for tutorials or articles considering HTML Frames and how to
handle them with Javascript.

E.g. samples how Frames can exchange information, can a Frame instruct
other Frame to update it's content etc.

This kind of information is welcome.

Cheers!


Hi, I made a function for this that loops over all frames in the current
window and tries to execute specific code on these frames.
So when function is called it tries to execute it on all frames it can find,
if function doesn't exist, it will do nothing.
(it works on firefox and iexplore). Well I use it quite often because it is
just one line of code and everything goes cross frame. There are some
drawbacks, one of them is you must yourself manage the executable codes in
the frames to avoid unwanted execution.
you could for example call: firecode('alert (\"I am a frame\");');
And every frame shows an alert.

or firecode('chang ecolor();');
and every frame that has changecolor() in it will execute it. What
changecolor is is up to you :)
Just make a function changecolor that changes the background of some frame,
and call above code.


here is the function:

function firecode(code)
{
framestruct(win dow, 1, code);
}

function framestruct(el, start, func)
{
var m = 20;
if(!start)
{
if((navigator && navigator.userA gent && navigator.userA gent.indexOf &&
navigator.userA gent.indexOf('G ecko') != -1) ||
(navigator.user Agent.indexOf(" Netscape")!= -1))
{
try
{
el.eval("try{" + func + "}catch(e){ }");
}
catch(e)
{}
}
else
{
try{el.execScri pt("try{" + func + "}catch(e){}"); }catch(e){};
}
}
else
{

for(;m>=0&&el.p arent;m--)
{
el = el.parent;
}
}
var f = el.frames;
var i;

for(i=0; i<f.length; i++)
{
framestruct(f[i], 0, func);
}

}

greetz Bert
Jul 23 '05 #3
In the following case, the browsers (IE6 and Firefox 1.0) do not
complain and show (via the alert) that an IMG element was
inserted as the first child of the top's body element. And yet it is
not displayed. Is this reasonable or not?

Csaba Gabor from Vienna
Main.htm:
<html><head><ti tle>Frame testing</title></head>
<frameset><fram e src="TestFrame. htm"></frameset></html>

TestFrame.htm
<html><head><ti tle>Image inserter</title>
<script type='text/javascript'>
function InsertImg() {
var myimg=top.docum ent.createEleme nt('img');
myimg.src="Test Img.jpg";
var firstKid=top.do cument.body.chi ldNodes[0];
top.document.bo dy.insertBefore (myimg,firstKid );
alert(top.docum ent.body.childN odes[0].tagName);
}
</script></head>
<body onLoad="InsertI mg()">
Frame loaded
</body></html>
Jul 23 '05 #4
Frame wrote:
I'm looking for tutorials or articles considering HTML Frames and how to
handle them with Javascript.

E.g. samples how Frames can exchange information, can a Frame instruct
other Frame to update it's content etc.

This kind of information is welcome.

Cheers!


"JavaScript Application Cookbook" has lots of frame examples.
You can read a sample chapter here:
http://www.oreilly.com/catalog/jscook/chapter/ch01.html

Jul 23 '05 #5
Csaba2000 wrote:
In the following case, the browsers (IE6 and Firefox 1.0)
do not complain and show (via the alert) that an IMG element
was inserted as the first child of the top's body element.
And yet it is not displayed. Is this reasonable or not? <snip> Main.htm:
<html><head><ti tle>Frame testing</title></head>
<frameset><fram e src="TestFrame. htm"></frameset></html>

<snip>

It depends on what you consider reasonable. You are adding an IMG as a
child of a FRAMESET and a sibling of a FRAME. The HTML DTDs don't allow
for that and a browser would be within its right to throw some sort of
malformed DOM exception at the attempt. Not throwing such an exception
is demonstrating tolerance, and being tolerant is probably a reasonable
response to the extremely low level of technical rigour in general
Internet authoring.

That the browsers do not show an IMG element inserted in such an
unexpected context is not particularly surprising either (though there
was a single Mozilla release that would display an absolutely positioned
DIV when inserted into a FRAMESET. Obviously that was recognised as a
bug and fixed in subsequent versions).

Richard.
Jul 23 '05 #6

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

Similar topics

3
1478
by: adnanx82 | last post by:
Hi, Under the same-origin policy, if a script tries to access properties in another frame or window that is from another host/protocol/etc, it will not be allowed by the browser and a permission denied error is given. I was wondering if anyone knew of a way to check if a particular frame's or window's properties were accessible before attempting to access them, to prevent getting the error.
4
3639
by: anonymous | last post by:
Thanks your reply. The article I read is from www.hakin9.org/en/attachments/stackoverflow_en.pdf. And you're right. I don't know it very clearly. And that's why I want to understand it; for it's useful to help me to solve some basic problem which I may not perceive before. I appreciate your help, sincerely.
8
12693
by: NeoAsimov | last post by:
Hello, There is what I want to do. I worked on the problem since 6 hours but I had a problem (probably stupid) and I dont know how to resolve it. I need to have an Mouse Event Click when I click on the frame of a window form ( like the title bar of a window).
1
2909
by: | last post by:
Hi all i posted this question yesterday. no answers yet. please do reply if you have any ideas. thanks a lot. Subject: stack frame stack trace can the information from the stack be obtained only when exceptions are thrown? kindly reply. ..
17
4186
by: Bruno | last post by:
I have a feature that is hosted on a different domain from the primary one in a frame, and need to retain values in a cookie. example: A web page at one.com contains a frame which has a page hosted at two.com If I view the frameset from one.com in Firefox, all works well with the content from two.com. But if trying to view this using IE (with standard security settings), the cookie set by two.com is not accessible.
12
7796
by: Don Juan | last post by:
I have a simple html document I have been using for some time on my (i.e.) abc.com domain that uses cookies. I recently purchased a new domain name and set up a service to redirect my new domain (i.e.) xyz.com to a sub-directory of the abc.com domain. In other words, when someone goes to URL xyz.com, they really end up in abc.com/xyz directory but the MSIE browser says they are xyz.com. The problem is that cookies quit working in this...
42
3900
by: smerf | last post by:
Using javascript, is there a way to trap an external page inside a frame? I've seen scripts to break out of frames, but nothing to keep a page trapped in a frame.
4
11574
by: Rico | last post by:
Hello, I have an MDE application where I use a bound object frame to display an image. This frame is updatable and bested on the contents of an OLE field. My problem is, some images display as the image and some display as an icon with the file name below. The process I'm following is as follows; Right click Choose "Insert Object..." Select "Create from File"
2
6154
by: arungenesis | last post by:
Hello people, I'm working with HTML and Javascript. I have some problems in handling frames. I have the following questions: 1. How do I retrieve the name of a FRAME in IE & Mozilla using a onclick event handler I have done this for IE and it is as follows: this.frames.name
0
9730
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10647
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9482
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7882
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7056
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5719
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5911
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3164
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.