IFRAME and window object (contentWindow)

Source: Internet
Author: User

VaR detialiframe = Document. All ("detialiframe ");

IFRAME is obtained from the document, that is, it appears as a sub-object of the document. Although it is a document object, it has its own event because it is an independent page, has its own window object (contentWindow); window. detialiframe or window. frames (detialiframe) will directly obtain the window object of IFRAME

IFRAME

The IFRAME element is the document in the document.

Window object

The browser will create a corresponding window object when it opens an HTML document. However, if a document defines one or more frameworks (including one or more frames or IFRAME tags), the browser creates a window object for the original document, create an additional window object for each frame. These additional objects are subwindows of the original window and may be affected by events in the original window. For example, closing the original window will close all subwindows. To create a new window (and corresponding window objects), you can use methods like open, showmodaldialog, and showmodelessdialog.

ContentWindow

The contentWindow attribute refers to the window object where the specified frame or IFRAME is located.

In ie, the contentWindow attribute of IFRAME or frame can be omitted. However, to edit an IFRAME object in Firefox, you must specify the contentWindow attribute.

Function enableedit ()

{

VaR editor;

Editor = Document. getelementbyid ("htmledit"). contentWindow;

// Make it editable for IE browser

Editor.doc ument. designMode = 'on ';

Editor.doc ument. contenteditable = true;

// For compatible with Firefox, it shoshould open and write something to make it work

Editor.doc ument. open ();

Editor.doc ument. writeln ('<HTML>

Editor.doc ument. writeln ('<style> body {Background: white; font-size: 9pt; margin: 2px; padding: 0px;} </style> ');

Editor.doc ument. writeln ('

Editor.doc ument. 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.content?#doc ument;

VaR S = fixinghtb. innerhtml; // save it before entering editable Mode

Ifrdoc. designMode = "on"; // The document enters the Editable mode.

Ifrdoc. open (); // open the stream

Ifrdoc. Write (s );

Ifrdoc. Close (); // close the stream

Ifrdoc. designMode = "off"; // The document enters the non-editable mode.

</SCRIPT>

</Body>

</Html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.