gpt4 book ai didi

javascript - 在tinymce编辑器中模糊时如何获取父iFrame ID?

转载 作者:行者123 更新时间:2023-11-28 03:39:33 25 4
gpt4 key购买 nike

我在一页上实现了 4 个 TinyMCE 编辑器。我想在用户离开TinyMCE编辑器并将编辑器的html放入文本区域时获取编辑器ID。在模糊时我可以获得编辑器 html。但我在 Firefox 和 IE 中找不到 iFrame ID。我尝试了这段代码。

tinyMCE.init({
mode : "textareas",
theme : "advanced",
plugins : "table,insertdatetime,fullscreen,searchreplace,emotions,paste,",
selector: "#vereinbarungen",
selector: "#narration",
theme_advanced_buttons1 : "insertdate,inserttime,|,hr,emotions,|,search,replace,|,cut,copy,paste,pastetext,pasteword,|,forecolor,backcolor,|,bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,undo,redo,|,fullscreen",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "bottom",
theme_advanced_toolbar_align : "left",
extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
plugin_insertdate_dateFormat : "%d.%m.%Y",
plugin_insertdate_timeFormat : "%H:%M:%S",
setup : function(ed) {
ed.onInit.add(function(ed, event) {
var dom = ed.dom,
doc = ed.getDoc(),
el = doc.content_editable ? ed.getBody() : (tinymce.isGecko ? doc : ed.getWin());
tinymce.dom.Event.add(el, 'blur', function(e) {

//this is the targeted iframe id this works in chrome but not works in other browsers.

target_id = el.frameElement.id;
html = $(ed.getBody()).html();
});
});
},

});

当我在 Chrome 上尝试此代码时,我得到了 target_id,但当我在其他浏览器上尝试时,el.frameElement 未定义。

这个问题有什么解决办法吗?

最佳答案

如果我理解你的问题,当编辑器模糊时你想要做的是更新底层 <textarea>与编辑器的当前值。

triggerSave() TinyMCE 中的 API 将自动执行您想要的操作,而无需执行您当前正在执行的任何手动 JavaScript 工作。

以下是示例:

关键代码是这样的:

setup: function (editor) {
editor.on('blur', function (e) {
console.log('Triggering a Save');
tinymce.triggerSave();
console.log(document.getElementById('content').value);
});
}

我使用 JavaScript 来显示 <textarea> 中的内容。 triggerSave()之后调用完成,但您不需要这些 console.log()调试以外的调用。

关于javascript - 在tinymce编辑器中模糊时如何获取父iFrame ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57406635/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com