2013-02-01 135 views
1

可能重复:
Iframe Function Calling From Iframe to parent page javascript function如何从iframe中调用Javascript函数?

我需要从一个iframe运行JavaScript函数(在一个HTML页面),我也跟着我在网上找到的指示,但我不能让这行得通。有任何想法吗?

下面的代码:

<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> 

而这里的Iframe.html的代码:normally.Why你说不能工作

<html> 
<body> 

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

</body> 
</html> 
+0

结算这个职位:http://stackoverflow.com/questions/2161388/iframe-function-calling-from-iframe-to-parent-page-javascript-function – kylemac

回答

0

我刚刚复制了你的代码,并且它工作正常。

+0

谢谢你,我在本地测试它(从我的电脑),它不工作。我把它上传到我的测试服务器上,它工作,所以显然它不能在本地运行。 – live2create

+0

现在,我试图在WordPress中使用该代码,它不再工作。所以问题不是来自JavaScript,而是来自WordPress的结局。我感谢您的帮助! – live2create

0

我测试,运行?请详细写出错误信息。
还有一个问题,“frameborder”不允许在html5中使用。我删除它。