blog
blog copied to clipboard
调用iframe子页面中的js函数
假设我们有一个index.html中写了这样一个iframe元素:
<iframe src="child.html" id="iframe" name="iframe"></iframe>
<button id="button">click</button>
<script>
var button = document.getElementById('button');
var child = window.iframe;
button.onclick = function(){
child.say();
}
</script>
在child.html中定义一个js函数,以供父页面进行调用:
function say(){
alert('hello');
}