/    Sign up×
Community /Pin to ProfileBookmark

how to activate a function on a different frame?

Hi everyone,
I’m writing a page that has an iframe in it.
I want to activate a function in the page within the iframe, from the main page.
what I mean is, the page “page1.php” has an iframe in it. in that page I have a link that calls a javascript function. I want that function to call another javascript function which is in the page within the iframe. (i.e. “page2.php”). also I want that function to execute inside its own page (“page2.php”). also I want to do all this without refreshing any of my pages, if possible.

can anyone help me in doing this?
I’m not very strong in javascript, so I would appreciate any help.

thanks
yar160.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@FromU2MEJan 16.2006 — A link to an example would certainly help here (and/or some code)... Perhaps we could change so that you can choose an easier way for your task - if we knew what the function's all about... ?
Copy linkTweet thisAlerts:
@KorJan 16.2006 — top.frames['iframename'].[I]thatfunction()[/I]

or

document.getElementById('iframeid').contentWindow.[I]thatfunction()[/I]
Copy linkTweet thisAlerts:
@KorJan 16.2006 — If u have parameters to be passed, or multiple functions to be triggered from a certain [I]object[/I] through a certain [I]event[/I], try this:

[I]object.onevent[/I] = function(){

document.getElementById('iframeid').contentWindow.thatfunction(parameter);

document.getElementById('iframeid').contentWindow.anotherfunction(anotererparameter)

}
Copy linkTweet thisAlerts:
@yar160authorJan 17.2006 — thanks KOR.

all I needed was: iframe.[B]contentWindow[/B].function().

The stupid tutorial I was using didn't mention this option. all I could find in it was contentDocument, which didn't work for me.

Anyway, it is working now, so..

Thanks again.

Yar160.
Copy linkTweet thisAlerts:
@KorJan 17.2006 — 
contentDocument, which didn't work for me.
[/quote]

mainly because functions are appended to the window object, not to the document object
×

Success!

Help @yar160 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...