Skip to content

API: Advanced methods

premasagar edited this page Sep 13, 2010 · 11 revisions

hasExternalDocument()

Returns true if the iframe contains a document that is from an external resource (either from the same domain, or not), as opposed to a document that has been created by JavaScript on-the-fly, or a null document (due to the iframe being out of the DOM, or the document never having been created). Otherwise false.

isSameDomain()

Returns true if the iframe contains a document that either a) has been created by JavaScript on-the-fly, or b) is from an external resource from the same domain as the host document. In such cases, JavaScript from the host document has full rights to read from and write to the iframe’s document. Otherwise false.

hasBlankSrc()

Returns true if the iframe element has a src attribute of "about:blank", or a blank string, or null. Otherwise false.

title()

Returns the iframe document’s title property.

title(newTitle)

Sets the iframe document’s title property.

doctype()

Returns the iframe document’s doctype string, e.g. <!DOCTYPE html>.

doctype(htmlVersion)

Uses the htmlVersion to determine the doctype that will be used when the iframe document is created.
The default is the HTML5 doctype: aomi.doctype(5). Also supported is HTML 4.01: aomi.doctype(4.01).

location()

Returns the iframe window’s location, if it can be determined (this will happen if the iframe is in the DOM and it has a document from the same domain as the host document). If not, then the method will either return the iframe element’s src attribute (if the iframe is out of the DOM and has a document from the same domain as the host document), or otherwise null.

resize([doWidth], [doHeight])

Resizes the iframe element to fit the iframe document’s body, which can be useful after elements are added or removed to the body, or CSS is changed.

If no arguments are passed, then the AOMI options autoheight and autowidth are used to determine the values of doWidth and doHeight. The default values are true for the height and false for the width.

Further explanation on the default behaviour: The AOMI object will attempt to act like a standard block-level element (e.g. a <div>). It will auto-resize its height when child elements are added and removed, but it won’t auto-resize its width to the child elements. Instead, like a <div>, the iframe will automatically stretch to fill its containing space, using the CSS width:100%.

options()

Returns an object of the current options. See API: Options.

options(newOptions)

Supply a subset of options to change in the AOMI object. See API: Options.

cache()

Caches the iframe document’s head and body. This is done so that if the iframe element is moved in the DOM and, as a result, the iframe document is destroyed (as it does in all browsers except Internet Explorer), then the head and body can be restored the next time that the iframe document is re-created. See restore().

restore()

Restores the iframe document’s cached head and body elements. See cache().

[TODO: Add a note about the different mechanisms that this method attempts, and the various implications of each: adoptNode, appendChild, importNode, cloneNode, reload]

clone()

Returns a replica AOMI object. This is a new AOMI object that has been created with the same arguments as the current AOMI object.

replace()

Replace the AOMI object’s iframe element with the iframe element from a replica AOMI object.

repaint()

Trigger the browser to repaint, or re-render, the iframe. It does this by setting a className on the element.

This can be useful to solve a bug in IE6: when an iframe that contains an external document is hidden, it may remain hidden, even when it should be visible.

reload([extreme])

Variations on reloading the iframe from a stored state.

  • If extreme is omitted, or false, then the iframe element’s src attribute will be re-applied. This triggers a reload of the iframe in the browser.
  • If extreme is true, then the arguments that had been supplied to the $.iframe() constructor are re-applied.

Clone this wiki locally