Javascript ajax之后的图像执行命令
我正在使用所见即所得编辑器,使用execCommand处理图像时遇到问题,下面是我的页面结构的简化示例:Javascript ajax之后的图像执行命令,javascript,ajax,execcommand,Javascript,Ajax,Execcommand,我正在使用所见即所得编辑器,使用execCommand处理图像时遇到问题,下面是我的页面结构的简化示例: <div id="buttons_panel"><input id="img_submit" type="button"/></div> <div id="img_handle" style="display:none;"> <div id="ajax_upload"></div> /* AJAX IMG UPLOAD
<div id="buttons_panel"><input id="img_submit" type="button"/></div>
<div id="img_handle" style="display:none;">
<div id="ajax_upload"></div> /* AJAX IMG UPLOAD FROM */
<div id="images"></div> /* DIV FOR ALL UPLOADED IMAGES DISPLAY */
</div>
<iframe id="text_content"></iframe>
然后,单击任一结果,我运行以下函数:
function insert_img(){$(".img_insert").click(function(){
var frame = document.getElementById('text_content'); frame.document.execCommand('InsertImage',false,"../PATH/TO/IMG");
});}
现在,这里是execCommand拒绝在firebug中工作的地方:“getElementById(“text\u content”).document UNDEFIEND”
我在该页面上运行的所有其他execCommand函数(例如:斜体粗体、字体颜色等)都能正常工作,但在这里却不行,有人能帮我找到解决方案吗?在
元素中获取文档
对象的标准方法是通过其内容文档
属性,而不是文档
。一些较旧的浏览器不支持这一点,但在那些浏览器中,您可以使用contentWindow.document
因此,除了那些不支持contentDocument
或contentWindow
的浏览器外,以下浏览器在所有浏览器中都能正常工作,而这些浏览器实际上并不存在:
function getIframeDocument(iframeEl) {
return iframeEl.contentDocument || iframeEl.contentWindow.document;
}
function insert_img(){
$(".img_insert").click(function() {
var frame = document.getElementById('text_content');
getIframeDocument(frame).execCommand('InsertImage',false,"../PATH/TO/IMG");
});
}
function insert_img(){$(".img_insert").click(function(){
var frame = document.getElementById('text_content'); frame.document.execCommand('InsertImage',false,"../PATH/TO/IMG");
});}
function getIframeDocument(iframeEl) {
return iframeEl.contentDocument || iframeEl.contentWindow.document;
}
function insert_img(){
$(".img_insert").click(function() {
var frame = document.getElementById('text_content');
getIframeDocument(frame).execCommand('InsertImage',false,"../PATH/TO/IMG");
});
}