在IE中iframe或者frame的contentWindow属性可以省略,但在Firefox中如果要对iframe对象进行编辑则
必须指定contentWindow属性。
但是虽然ie是默认的,有时候还是会出现问题,建议无论是哪个浏览器,都需要写上该属性。
function EnableEdit()
{
var editor;
editor = document.getElementById("HtmlEdit").contentWindow;
// 针对IE浏览器, make it editable
editor.document.designMode = 'On';
editor.document.contentEditable = true;
// For compatible with FireFox, it should open and write something to make it work
editor.document.open();
editor.document.writeln('<html><head>');
editor.document.writeln('<style>body {background: white;font-size:9pt;margin: 2px; padding: 0px;}</style>');
editor.document.writeln('</head><body></body></html>');
editor.document.close();
}
<iframe ID="HtmlEdit" MARGINHEIGHT="1" MARGINWIDTH="1" width="100%" height="312">
</iframe>
<html>
<body>
<script>
var ifr = document.createElement("iframe");
document.body.appendChild(ifr);
var ifrdoc = ifr.contentWindow.document;
var s = fixingHTB.innerHTML; //进入可编辑模式前存好
ifrdoc.designMode = "on"; //文档进入可编辑模式
ifrdoc.open(); //打开流
ifrdoc.write(s);
ifrdoc.close(); //关闭流
ifrdoc.designMode ="off"; //文档进入非可编辑模式
</script>
</body>
</html>
分享到:
相关推荐
jQuery获取iframe的window对象 var win = $(‘#ifr’)[0].contentWindow; JS原生方法获取iframe的window对象 document.getElementById(“ifr”).contentWindow; 可见 $(‘#ifr’)[0].contentWindow 和 document....
iframe元素就是文档中的文档。 window对象: 浏览器会在...contentWindow: 是指指定的iframe或者iframe所在的window对象 Demo1 父页面fu.html: <!DOCTYPE html> <html lang="en"> <head> <meta cha
如图中的 this.iframeWin = this.$refs.iframe.contentWindow 【拿到iframe的window对象】 3.vue如何向iframe内传送信息 可以通过H5新属性 postmessage 注释:【postMessage是有点类似于UDP协议,就像短信,是异步的...
但是这个控在内、外交互时,往往各个浏览器所用的关键字不同,很是麻烦,为了能够得到子iframe中的window对象,各家浏览器有着各家的指定,有的是window,有的是contentWindow等等也许还有我们不知道的。 但是从子...
复制代码 代码如下:$(window.parent.document).contents().find(“#iframeID”)[0].contentWindow.initPagerList(); 说明: iframeID 为iframe的ID; initPagerList 为 iframe 页面内的方法。 <html> <...
某天,领导提了一个需求,主页面里面嵌套iframe,父子页面双向... otherWindow:其他窗口的引用,如 iframe的contentWindow、执行window.open返回的窗口对象、或者是命名过或数值索引的window.frames。 message:将
frame是 Iframe 或框架节点元素的窗口(例如document.querySelector('iframe').contentWindow ) 如果未设置,则无法send消息但仍可接收和响应 origin是框架的 url(带有协议)(例如https://gojobhero.com
frameWindow.document.execCommand('print', false, null)) { // document.execCommand returns false if it failed -http://stackoverflow.com/a/21336448/937891 frameWindow.print(); } } catch (e) { frame...
代码如下:document.getElementById(“iframeId”).contentWindow.functionName(); 代码如下:window.frames[‘framename’].functionName();
var Y=window,T={innerHTML:""},N="document",H="documentElement",C="getElementsByTagName",V,A,S,G,c,X=navigator.appName;if(X=="Microsoft Internet Explorer")S=true;else if(X=="Opera")c=true;else G=true;A...