从CKEDITOR.dialog的onOk插入iframe的
问题描述:
我使用CKEditor,并且在用户单击我的对话框中的OK按钮时,我的编辑器中的div元素中插入iframe时出现问题。这不起作用。当用户点击按钮时什么都没有发生(我没有错误信息)。所以他应该关闭我的弹出窗口并在我的编辑器中插入包含我的iframe的div从CKEDITOR.dialog的onOk插入iframe的
你能帮我吗?
这是我的代码 :
CKEDITOR.dialog.add( 'postVideoDialog',函数(编辑){
return { title : 'Add Video', minWidth : 400, minHeight : 80, contents : [ { id : 'video', label : 'Add Video', elements : [ { type : 'text', id : 'url', label : 'Enter a URL from Vimeo :', validate : function() { var url = this.getValue(); var regex1=/^(http:\/\/)vimeo.com\/[0-9]{3,}$/g; var regex2=/^(http:\/\/)player.vimeo.com\/video\/[0-9]{3,}$/g; if(regex1.test(url) || regex2.test(url)){ return true }else{ alert("Url incorrect"); return false; } }, required : true, commit : function(data) { data.url = this.getValue(); } }, ] } ], onOk : function() { var dialog = this, data = {}, iframe = editor.document.createElement('iframe'), div = editor.document.createElement('div'); this.commitContent(data); var regex=/^(http:\/\/)vimeo.com\/[0-9]{3,}$/g; //http://vimeo.com/25329849 if(regex.test(data.url)){ var idVideo = data.url.match(/[0-9]{3,}$/g); data.url = "http://player.vimeo.com/video/" + idVideo; } div.setAttribute('class', 'video'); iframe.setAttribute('src', data.url + "?byline=0&portrait=0&color=ffffff"); iframe.setAttribute('width', '620'); iframe.setAttribute('width', '349'); iframe.setAttribute('frameborder', '0'); div.insertElement(iframe); //problem is here ! editor.insertElement(div); } }; });
答
发现它..
阅读文档请:docs.ckeditor.com/#!/api/CKEDITOR.dom.element
元素没有insertElement方法。这是编辑的方法试试这个:
iframe.appendTo(div); //problem is solved here!
editor.insertElement(div);
,而不是你以前的代码:
div.insertElement(iframe); //problem is here !
editor.insertElement(div);
是准确的!问题是什么?你有什么错误。什么不起作用? – spons