`
落地窗
  • 浏览: 435758 次
  • 性别: 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>
分享到:
评论

相关推荐

    frame与contentwindow对象

    ContentWindow 对象是指指定的 Frame 或者 iframe 所在的 Window 对象。在 IE 中,iframe 或者 frame 的 ContentWindow 属性可以省略,但在 Firefox 中,如果要对 iframe 对象进行编辑则必须指定 ContentWindow 属性...

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

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

    frame 的 parent 是谁?

    在这个例子中,`window.parent`获取了顶层`frame`,然后通过`document.getElementsByTagName`找到第二个`frame`(因为索引从0开始),接着通过`contentWindow`属性获取`frame`内的`window`对象,最后通过`document....

    jQuery获取iframe的document对象的方法

    这里,`#myframe`是`iframe`的ID,`prop('contentWindow')`返回的是`iframe`的窗口对象,而`window`对象在JavaScript中包含了`document`属性,所以通过`.document`可以获取到`iframe`内部的`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

    dom网页frame枚举

    每个frame或iframe都有自己的窗口对象(window)和文档对象(document),我们可以使用`contentWindow`和`contentDocument`属性来访问它们。例如,`frameElement.contentWindow`可以返回frame或iframe的窗口对象,`...

    js iframe 打印 打印预览 页眉页脚的设置

    然后,为其设置`src`属性,指向需要打印的页面URL,或者将其`contentDocument`或`contentWindow`指向一个包含HTML内容的Blob对象,以便在打印时使用。 ```javascript var iframe = document.createElement('iframe'...

    iframe子父页面调用js函数示例.docx

    需要注意的是,`contentWindow` 属性是指定的 frame 或者 iframe 所在的 window 对象,IE 下可以省略。 总结 在上面的示例中,我们演示了如何在 iframe 子页面中调用父页面的 js 函数,以及如何在父页面中调用 ...

    JS操作iframe里的dom(实例讲解)

    首先,要访问`iframe`内部的DOM,我们必须获取到`iframe`对象,然后通过`contentWindow`属性访问到`iframe`内部的`window`对象,再通过`document`属性获取其`document`对象。这样,我们就能够对`iframe`内的HTML元素...

    在iframe、frame之间,js的相互访问、修改

    3. DOM操作:在同源环境下,JavaScript可以直接通过`window.frames`对象来访问`iframe`或`frame`中的`window`对象,从而操作其DOM。例如,`window.frames["iframeName"].document.getElementById("elementId")`可以...

    iframe应用

    #### 一、获取iframe的window对象 要实现父窗体与子窗体之间的通信,首先需要能够访问到子窗体的`window`对象。这可以通过以下方式来实现: ```javascript var iframe = document.getElementById('iframe1')....

    iframe根据页面内容自适应高度和宽度

    在网页开发中,`iframe`(Inline Frame)是一种嵌入其他网页的标签,常用于将外部内容如视频、地图或文章等内容嵌入到当前页面中。然而,由于`iframe`的大小固定,当嵌入的页面内容高度或宽度超过`iframe`设定的尺寸...

    js 实现iframe 之间传值

    `window.postMessage()`接收两个参数:要传递的数据和目标窗口的引用(通常是`iframe`的`contentWindow`属性)。例如,父页面向`iframe`传递消息: ```javascript // 父页面 var iframe = document....

    iframe框架使用(完美版)

    1. **JavaScript监听滚动事件**:通过监听iframe的`load`事件,当内容加载完成后,获取iframe的contentWindow或contentDocument对象,计算其高度并赋值给iframe的height属性。 2. **使用postMessage通信**:如果...

    frameset父页面和子页面的方法之间调用个属性的调用(页面上可以包含iframe)

    // 通过名称获取子页面的window对象 ``` 2. `contentWindow` 和 `contentDocument` 属性:这两个属性主要用于访问`iframe`的内容。`contentWindow`指向`iframe`的`window`对象,`contentDocument`则指向`iframe`...

    js实现iframe自适应高度

    3. **监听`load`事件**:当`iframe`内的页面加载完成后,我们可以通过`contentWindow`和`contentDocument`属性访问到`iframe`内的`window`和`document`对象,进而获取其内容的高度。 ```javascript iframe.onload...

    js操作iframe的一些知识

    而`contentWindow`属性则可以直接获取到Iframe内部的窗口对象。 ##### 3. 操作Iframe中的元素 获取了Iframe窗口对象后,就可以像操作普通页面一样操作Iframe内的元素了。例如,隐藏或显示某个元素: ```...

    iframe内容高度 iframe自适应高度终极解决Iframe设置高度后无法缩小问题

    需要注意的是,`document.frames`是老式的方法,用于访问`&lt;frameset&gt;`内的`&lt;frame&gt;`元素,而在现代浏览器中,更推荐使用`contentWindow`或`contentDocument`来访问`&lt;iframe&gt;`的内容。在这个例子中,我们使用了`...

    iframe父与子、子与子之间控制以及js相互调用实际例

    - `contentWindow` 属性:通过`iframe`元素的`contentWindow`属性,我们可以获取到iframe内部的`window`对象,从而调用其上的方法或修改DOM。 - `window.postMessage()` 方法:这是一个安全的跨域通信方式,允许两...

Global site tag (gtag.js) - Google Analytics