/    Sign up×
Community /Pin to ProfileBookmark

Accessing iframe pages

Hi all,
First time poster, long time watcher ?
I’m having some trouble with a javascript function. Basically, I have an html page that contains an iframe. I am trying to call a function that is located inside the iframe’s document from the original html page. For now I’m just trying to call a function that does a simple alert, but I can’t seem to get it to work whatsoever. I just need it to work for IE7 – anyone have any hints?
Eternally grateful,
Cody

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@codyhawkeauthorJan 03.2009 — Here is an actual mock-up of what is not working:


<html>

<head>

<script type="Javascript">

function CallAlert(){

top.frames['earthFrame'].alertMe();

}

}

</script>

</head>

<body>

<div id="theIframeDiv">

<iframe src="http://www.foo.com" width="300" height="300"></iframe>

</div>

</body>

</html>




foo.com source -

<html>

<head>

<script type="Javascript">

function alertMe(){

alert("hiya!");

}

</script>

</head>

<body>

blah blah copy

</body>

</html>
Copy linkTweet thisAlerts:
@FangJan 03.2009 — function CallAlert(){
frames[0].alertMe();
}

[I]frames['earthFrame'][/I] Where does this come from?
Copy linkTweet thisAlerts:
@codyhawkeauthorJan 03.2009 — oops. I forgot to mention that the iframe also has <iframe id="earthFrame" name="earthFrame">

Sorry for the mix-up.
Copy linkTweet thisAlerts:
@codyhawkeauthorJan 03.2009 — frames[0].alertMe() doesn't seem to be working :/
Copy linkTweet thisAlerts:
@codyhawkeauthorJan 03.2009 — Another aspect that may be part of the problem: The HTML page containing the iframe resides locally on a machine and the iframe that is referenced is an actual website.
Copy linkTweet thisAlerts:
@FangJan 03.2009 — Another aspect that may be part of the problem: The HTML page containing the iframe resides locally on a machine and the iframe that is referenced is an actual website.[/QUOTE]Then you can't reference it.
Copy linkTweet thisAlerts:
@codyhawkeauthorJan 03.2009 — Ouch. Any thoughts as to a possible hacky workaround?
Copy linkTweet thisAlerts:
@FangJan 03.2009 — Not possible.
Copy linkTweet thisAlerts:
@codyhawkeauthorJan 03.2009 — Grr. Oh well, thanks for clarifying - best to cut this off at the pass before it got any hairier. Much appreciated, Fang. ?
×

Success!

Help @codyhawke 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.4,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...