window对象(contentWindow)

IFRAME

IFRAME 元素是文档中的文档

window 对象

浏览器会在其打开一个 HTML 文档时创建一个对应的 window 对象。如果一个文档定义了一个或多个框架(即,包含一个或多个 frame 或 iframe 标签),浏览器就会为原始文档创建一个 window 对象,再为每个框架创建额外的 window 对象。这些额外的对象是原始窗口的 子窗口,可能被原始窗口中发生的事件所影响。如果想要创建新窗口(以及对应的 window 对象),可以使用像 open, showModalDialog 和 showModelessDialog 这样的方法。

contentWindow

contentWindow属性是指指定的frame

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>

注:本文主要内容来自网络

时间: 2024-08-09 10:42:00

window对象(contentWindow)的相关文章

IFrame与window对象(contentWindow)

var detialIframe=document.all("detialIframe"); 此处的IFrame是从document取得的,即作作为document的子对象出现,虽然是文档(document)对象,但由于它是独立的页面,因而拥有自己的事件,拥有自己的窗口对象(contentWindow); Window.detialIframe 或Window.frames(detialIframe)将直接取得IFrame的Window对象 IFRAME IFRAME 元素也就是文档中

JavaScript权威设计--Window对象之Iframe(简要学习笔记十四)

1.Window对象属性的文档元素(id) 如果在HTML文档中用id属性来为元素命名,并且如果Window对象没有此名字的属性,Window对象会赋予一个属性,它的名字是id属性的值,而他们的值指向表示文档元素的HTMLElement对象. Window对象是以全局对象的形式存在于作用域链的最上层,这就意味着HTML文档中使用的id属性会成为可以被脚本访问的全局变量. 如: <button id="but"/> 就可以通过全局变量but来引用此元素. 2.多窗体窗口(if

js学习--DOM操作详解大全二(window对象)

一.window - 计时器 1?setTimeout()可以用来在指定的时间之后单次调用函数.setTimeount(f,1000);//一秒后调用函数fclearTimeout();取消函数的执行 示例:用setTimeout函数在1秒后改变字体的大小为60px. <html> <head> <script> function invoke(f,start){ setTimeout(f,start); } function changeSize(){ //改变元素的

window对象的几个重要方法

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>JavaScript window对象常用方法及事件</title><script type="text/javascript"> window.onload=function(){//文档加载完成后执行此方法   alert("文档加载完毕了"); }

【温故而知新-Javascript】使用 Window 对象

1. 获取 Window 对象 可以用两种方式获得Window对象.正规的HTML5方式是在Document对象上使用defaultView属性.另一种是使用所有浏览器都支持的全局变量window . <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>获取Window对象</title> </head

全局变量都是window对象的属性

var x = "haha"; var test  = function(){ alert(this.x); } 上述,则会弹出 haha的值. 因为在JavaScript的变量作用域里有一条规则“全局变量都是window对象的属性”. 所以当执行test();方法时,相当于执行window.test(); 所以test方法中的this相当于指向了window对象,而window对象又有x变量. 即:this所在的函数是当作哪个方法的对象所调用的,即该对象就是this所引用的对象. 参

window对象的常用属性,常用方法

window对象的常用属性: window.self 返回当前窗口的引用 window.parent   返回当前窗体的父窗体对象 window.top 返回当前窗体最顶层的父窗体的引用 window.outerwidth       返回当前窗口的外部宽 window.outerheight  返回当前窗口的外部高 window.innerwidth       返回当前窗口的可显示区域宽 window.innerheight  返回当前窗口的可显示区域高 提示:通过直接在Chrome控制台中

2015/12/23--部分window对象

<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>部分window对象</title> <script type="text/javascript"> //无穷循环中的计时 var c = 0; var t; function timeCount(){ document.getE

HTML DOM Window对象

本篇主要介绍HTML DOM Window对象的属性和方法. 目录 1.介绍:描述HTML DOM Window对象. 2.属性:介绍window对象的属性.如:对Console.Document.History.Location和Navigator对象的引用. 3.方法:介绍window对象的方法.如:获取焦点.改变滚动条.设置定时器等等. 1. 介绍 Window对象表示浏览器打开的窗口.标签或者框架(若当前页面里包含多个iframe,会为每个iframe创建Window对象). Windo