1

Possible Duplicate:
Iframe Function Calling From Iframe to parent page javascript function

I need to run a JavaScript function (in an HTML page) from an iframe, I followed the instructions I found online but I couldn't make it work. Any ideas?

Here's the code:

<html>
<head>
<script type="text/javascript"> 
function testFunction()
{
    var jsmessage = "Test succeed.";
    alert(jsmessage);
    return false;
}
</script>
</head>
<body>

<iframe id="myframe" src="iframe.html" height="260" width="620" frameborder="0"></iframe>

</body>
</html>

And here's the iframe.html code:

<html>
<body>

<input type="button" onclick="parent.testFunction();" value="Test function">

</body>
</html>
Community
  • 1
  • 1
  • Checkout this post: http://stackoverflow.com/questions/2161388/iframe-function-calling-from-iframe-to-parent-page-javascript-function – kylemac Feb 01 '13 at 01:59

2 Answers2

0

I have tested it, operation normally.Why you say it couldn't work? Please write the error information in detail.
One more question, "frameborder" is not allowed to use in html5. I delete it.

Bruce Li
  • 137
  • 4
  • 13
0

I just copied your code, and it works correctly.

Code.Town
  • 1,216
  • 10
  • 16
  • Thank you, I tested it locally (from my computer) and it was not working. I uploaded it on my test server and it worked, so apparently it cannot be run locally. – live2create Feb 01 '13 at 02:39
  • Now, I tried to use that code in WordPress and it's not working again. So the problem doesn't come from the JavaScript but on WordPress' end apparently. I appreciate your help! – live2create Feb 01 '13 at 02:41