【发布时间】:2015-07-20 14:36:30
【问题描述】:
我正在尝试在父页面的 iframe 中实现 JavaScript。我读了Invoking JavaScript code in an iframe from the parent page,但是,得到以下错误。
Error: Permission denied to access property "showIt"
document.getElementById('targetFrame').contentWindow.showIt();
我已经尝试在 jsfiddle 和我的服务器上实现这一点(不知道这是否重要,但它使用 https),但得到相同的结果。我还尝试删除子 iframe 上的 $(function(){}) 包装器,但没有任何变化。
我的实际应用如下所述。
如何做到这一点?
我的申请:
我的父页面 https://jsfiddle.net/5f4ct5ph/6/) 包含一个 iframe。
<iframe width="100%" height="300" src="https://jsfiddle.net/5f4ct5ph/5/embedded/result/" id="targetFrame"></iframe>
<button id="show">Show</button>
<button id="hide">Hide</button>
$(function () {
$('#show').click(function () {
document.getElementById('targetFrame').contentWindow.showIt();
});
$('#hide').click(function () {
document.getElementById('targetFrame').contentWindow.hideIt();
});
});
iframe 页面 (https://jsfiddle.net/5f4ct5ph/5/) 包含一个 tinymce 编辑器。
<div id="content">Initial content goes here</div>
#content {height:200px;width:400px;border: 1px solid;}
$(function () {
tinymce.init({
selector: "#content",
width : 400,
height: 200,
setup : function(ed) {
ed.on('init', function(e) {
e.target.hide();
});
}
});
function showIt() {
tinymce.get('content').show();
};
function hideIt() {
tinymce.get('content').hide();
};
});
【问题讨论】:
标签: javascript jquery iframe https tinymce