...

View Full Version : javascript function access question



txp200
04-27-2004, 05:39 PM
i have a site that uses multiple frames and html files for centering. is there a way to write a javascript function so that when a link is click it will open a page and then access a fuction on another page that changes 2 frames at once? i have a function written already but it only works when im on the page that the javascript is written in.

im not very familiar with javascript and i have searched around a lot not able to find a specific answer to my question. any help is appreciated. thanks.

txp200
04-27-2004, 05:55 PM
i read my post and it seems confusing so ill try to clear it up. my site has an opening page which has a couple links to different menu options. when an option is clicked a page is opened called index2.html. this page then has 3 frames left, center, and right. and within in center i have 3 more top, middle and bottom. then in middle is where i have 2 more frames, on the left is an html file with a pic in it and on the right i have a body.html file with a menu and the javascript code in it. so when a link is clicked from the opening page it opens up index2 and i need it to use the function that is in the the body.html file to change the left (picture frame) and the right body frame depending on the link they clicked on the opening page. is this possible?

jbot
04-27-2004, 06:22 PM
why do you have to use frames? they're a big no-no. they have been since they first came out.

you can achieve the same effect these days using layers and iframes or object tags.

txp200
04-27-2004, 06:35 PM
i was used just using empty frames to center my site. like www.cecildreeme.com
so it will be centered no matter what the persons screen resolution is. could i do that with layers an iframes?

sad69
04-27-2004, 06:58 PM
Yes it is possible. In your frameset, where you define your frames, you must ensure to give those frames unique names.

That way you can refer to those frames by their names, for example:
index.html:


<frameset rows="20%,80%">
<frame src="file1.html" name="frame1">
<frame src="file2.html" name="frame2">
</frameset>

window.top.frames["frame1"].functionName();


So basically file1.html might have a function in it called functionName(). The window.top... line could be called in file2.html, so it's calling functionName() in file1.html.

Now the important thing to note is that all files in all frames must exist on the same server/domain. You can't load up Google in one of your frames and try to call its functions as you will get an Access Denied error. If you get that right now trying to make your site work, then ensure that each file is on the same domain and if your links are not relative but absolute, that your links have the same domain reference (ie. be consistent: only use IP addresses or domain names, don't mix and match because that will give you some grief!)

Hope that helps,
Sadiq.

sad69
04-27-2004, 07:08 PM
I was trying to figure out why anyone would bash frames.. so I Google'd it and came up with the following link:
http://www.useit.com/alertbox/9612.html

So now I sort of understand why frames can be bad... but I still like them!

Any comments?

Sadiq.

txp200
04-27-2004, 08:16 PM
sad69 i tried using the window.top.frames thing but it's not working. this is the code im using in my opening page:

function change2(name)
{
location = ("index2.htm");
window.top.frames["_body"].go('name');
}
when a link is clicked that function is executed. And it goes to index2 but it doesn't run the go function located in the _body frame. i also have the frame named _body so i can't be that.
this is the go function:

function go(name)
{
parent._left.location= (name + "left.htm");
_right.location= (name + ".htm");
}

the go function works when i click a link that is located in the _body frame.

sad69
04-27-2004, 08:19 PM
I dunno why, but try changing top to parent and see how that works out..

Sadiq.

glenngv
04-28-2004, 07:36 AM
function change2(name)
{
location = ("index2.htm");
window.top.frames["_body"].go('name');
}

It does not work because index2.htm, which contains the nested frames one of which you were referencing, has not finished loading.

Instead of using bunches of frames, why not use iframe (http://www.w3.org/TR/html401/present/frames.html#edef-IFRAME) and then put the links in the same page where the iframe is?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum