/    Sign up×
Community /Pin to ProfileBookmark

onload trigger function in iframe

Ive got an Iframe in a page with an id and name of: ‘ horrorframe ‘,
and on load of the page it’s in, id like a function in the iframe to run.

but i dont want to add an onload to the iframes page.

how can i onload of the main page run a function in the Iframe?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@Mr_JJul 09.2005 — Is the function going to be run every time a page is loaded into the iframe or only when certain pages are loaded?

Adding "onload" to the iframe pages may be the simplest of choices
Copy linkTweet thisAlerts:
@ck_net_2004authorJul 10.2005 — Only when the page that contains the Iframe loads id like it to run a function

inside the Iframe.

for example:

page 1:
[code=php]
<html>
<head>
<title>main page</title>
</head>
<body onload="in iframe run this function: dothis();">
<iframe id="horrorframe" name="horrorframe" src="page2.htm" width="250" height="250"></iframe>
</body>
</html>
[/code]

page 2:
[code=php]
<html>
<head>
<title>iframe page</title>
<script type="text/javascript">
function dothis(){
alert("hello world");
}
</script>
</head>
<body>
hello
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@Mr_JJul 10.2005 — Try this


[code=php]<html>
<head>
<title>main page</title>

<script type="text/javascript">
<!--

function test(){
window.frames['horrorframe'].dothis()
}

//-->
</script>

</head>
<body onload="test()">
<iframe id="horrorframe" name="horrorframe" src="page2.htm" width="250" height="250"></iframe>
</body>
</html> [/code]
Copy linkTweet thisAlerts:
@ck_net_2004authorJul 13.2005 — Thanks tons Mr. J that worked perfectly
×

Success!

Help @ck_net_2004 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.2,
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,
)...