How do I access a function in another frame of a set...?
I have a <frame name="right" src="right.htm.....
and <frame name="left" src="left.htm....
Within frame left I have a function called "roll(arg1,arg2)"
How can I access this function from the right frame.
I've tried parent.left.roll('x','y')
as per forms etc, but it doesnt work...
Any ideas?
Suzanne posted this at 21:12 — 26th May 2000.
She has: 5,507 posts
Joined: Feb 2000
Yes, get the O'Reilly book -- JavaScript, the Definitive Guide!
If you have the function IN another frame, which is what I think you are saying you have, you can either use an external .js file (so it can be called from any file that you have <script language="JavaScript" type="text/javascript" src="script.js"></script> in the <head> tag), or you can repeat it in the file that needs it.
JavaScript is client side, so it can't reference things that aren't there when it loads.
I don't know if that answered your question or not.
Suzanne
------------------
Zero Cattle
Suzanne
Tables DeMystified
Lloyd Hassell posted this at 09:20 — 27th May 2000.
They have: 231 posts
Joined: Feb 2000
Celstk550: you are on the right track. You can access a function across frames without repeating the code.
From the right frame:
<a href="javascript:parent.right.roll()">LEFT SCRIPT</a>
Try adding the "javascript:" bit to your URL. It may be the problem. If not then post a URL so I can take a look at your code.
:: Lloyd Hassell :: http://www14.brinkster.com/lloydh ::
Celstk550 posted this at 20:41 — 27th May 2000.
They have: 30 posts
Joined: Jan 2000
Thanks guys but...
Let me tell you what I am trying to do...
I have animated rolling menu items in my left frame say...parent.left.document.menu1 is one image.
When you mouseover it rolls as expected.
When you click on it hrefs to the right frame but stops rolling.
I include the following function in parent.left
var roll_timer="";
function roll(menu_item){
img_active(menu_item);
clearTimeout(roll_timer);
roll_timer=setTimeout('roller()',1000);
}
where: img_active etc are simple array exchange progs
and wanted to add the following to the right:
onLoad="javascript arent.left.roll()"
so that the left menu indicates which page their on by the appropriate menu button constantly rolling every second.
Of course the same would go for other pages and menu2, menu3.
So - Suzanne...If I use "src" tags I still have the same problem with referencing parent.left....etc
and wanted the active "right" page to do the asking so as to avoid errors.
Lloyd...I'll give the HREF idea a go but I would somehow still like the right page to call the lefts' function.
Thanks in advance.
Celstk550 posted this at 20:44 — 27th May 2000.
They have: 30 posts
Joined: Jan 2000
I dont know where that poking tongue smiley came from ????
I'll try again;
should read javascript : parent.left.roll()
Cheers
Suzanne posted this at 01:43 — 28th May 2000.
She has: 5,507 posts
Joined: Feb 2000
Thanks for the clarification! And way funny on the heh, heh...
Suggestions (which may be not valid, I'm okay with being wildly wrong -- heh, heh):
- swap the image instead of roll it?
- reset the frame (if they click on the link in the navigation frame, have the image change (swap) entirely, if they click on a page in the right frame, have the left frame reset to whatever images. hmmm, this is probably what you are trying to do)
- reload the frame with a new document (lots of work for not much effect)
- onClick in the <a> tag? (instead of href="javascript:"?
The O'Reilly book is still recommended, though. I also have the Pocket Reference, which kicks butt. So is www.irt.org that has reems of info on frames and JavaScript and targeting and may have something to aid you to a good solution.
Otherwise, I'd let Lloyd take a peek at the whole shebang.
Suzanne
------------------
Zero Cattle
Suzanne
Tables DeMystified
Lloyd Hassell posted this at 04:19 — 29th May 2000.
They have: 231 posts
Joined: Feb 2000
I cant understand what you want your script to do? Your second post is entirely different to your first. Did you write the script yourself? Or did you get it from somewhere else? The only way I can get an idea is by looking at it. Can you post a URL?
:: Lloyd Hassell :: http://www14.brinkster.com/lloydh ::
Vincent Puglia posted this at 14:33 — 29th May 2000.
They have: 634 posts
Joined: Dec 1999
Hi,
I also am a bit confused. You actually mention 2 functions (roll, roller). You write "roll(x,y)" but define it as "roll(menu_item)" Roller, on the other hand, has 2 arguments. Which are you trying to call?
At any rate.... you need to access the current menu_item so that it can be used to call the left frame's roll().
Going back to Suzanne's suggestion of *js files: you would need to change the code so that you can send the framename as a parameter. eg: functionname(framename, menu_item, time)
And yes Suzanne, O'Reilly's books and irt.org are excellent references
Vinny
------------------
GrassBlade: cut&paste javascript
The Javascript Place Forums
Where the world once stood
the blades of grass cut me still
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.