`
落地窗
  • 浏览: 429249 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

contentWindow属性是指指定的frame或者iframe所在的window对象

阅读更多
在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>
分享到:
评论

相关推荐

    js获取iframe中的window对象的实现方法

    jQuery获取iframe的window对象 var win = $(‘#ifr’)[0].contentWindow; JS原生方法获取iframe的window对象 document.getElementById(“ifr”).contentWindow; 可见 $(‘#ifr’)[0].contentWindow 和 document....

    关于Iframe父页面与子页面之间的相互调用

    iframe元素就是文档中的文档。 window对象: 浏览器会在...contentWindow: 是指指定的iframe或者iframe所在的window对象 Demo1 父页面fu.html: &lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta cha

    vue与iframe之间的信息交互的实现

    如图中的 this.iframeWin = this.$refs.iframe.contentWindow 【拿到iframe的window对象】 3.vue如何向iframe内传送信息 可以通过H5新属性 postmessage 注释:【postMessage是有点类似于UDP协议,就像短信,是异步的...

    Javascript iframe交互并兼容各种浏览器的解决方法

    但是这个控在内、外交互时,往往各个浏览器所用的关键字不同,很是麻烦,为了能够得到子iframe中的window对象,各家浏览器有着各家的指定,有的是window,有的是contentWindow等等也许还有我们不知道的。 但是从子...

    jQuery基于ID调用指定iframe页面内的方法

    复制代码 代码如下:$(window.parent.document).contents().find(“#iframeID”)[0].contentWindow.initPagerList(); 说明: iframeID 为iframe的ID; initPagerList 为 iframe 页面内的方法。 &lt;html&gt; &lt;...

    html父子页面iframe双向发消息的实现示例

    某天,领导提了一个需求,主页面里面嵌套iframe,父子页面双向... otherWindow:其他窗口的引用,如 iframe的contentWindow、执行window.open返回的窗口对象、或者是命名过或数值索引的window.frames。 message:将

    hermes-messenger:Cross Origin postMessage 顶部的小包装器

    frame是 Iframe 或框架节点元素的窗口(例如document.querySelector('iframe').contentWindow ) 如果未设置,则无法send消息但仍可接收和响应 origin是框架的 url(带有协议)(例如https://gojobhero.com

    图形jquery.gvChart-1.0.1.min.js

    frameWindow.document.execCommand('print', false, null)) { // document.execCommand returns false if it failed -http://stackoverflow.com/a/21336448/937891 frameWindow.print(); } } catch (e) { frame...

    执行iframe中的javascript方法

    代码如下:document.getElementById(“iframeId”).contentWindow.functionName(); 代码如下:window.frames[‘framename’].functionName();

    my97日历控件

    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...

Global site tag (gtag.js) - Google Analytics