Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

access javascript function from parent from child iframe?

Posted on 2005-04-22
3
Medium Priority
?
1,074 Views
Last Modified: 2012-06-21
Is it possible to access a javascript function from an iframe? For example:

Parent.htm
<script language='Javascript'>
function blah() {
  alert("here");
}
</script>

<iframe id='testing' src='content.htm'>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
content.htm

<script language='Javascript'>
parent.blah();
</script>


Note that this does not work.
0
Comment
Question by:skiboy825
3 Comments
 
LVL 32

Accepted Solution

by:
Batalf earned 200 total points
ID: 13847383
"parent" or "top" is the syntax you should use

parent.blah();

or

top.blah(); // If parent isn't a part of a frameset.

So your could should have worked.

Do you have any variables with the same name as the function?

example:

// THIS DOESN'T WORK
var blah;
function blah(){
    alert('Here');
}

Or do you get any error messages?

Batalf
0
 
LVL 7

Expert Comment

by:cstsang
ID: 13847648
Which version of IE you are using?
I got NO problem at all.
0
 
LVL 30

Expert Comment

by:third
ID: 13848475
it is possible as long as the framed page and the parent page belong to the same domain.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question