Inheritance diagram for burst.io.IframeURIRequest:
This is not needed in environments supporting XMLHttpRequest; in that case use XmlHttpURIRequest .
This implementation relies on the primitive (and stateless) utility functions for iframes in burst.xml.HtmlUtil .
There are several considerations:
onload='parent.done()'
. This would require cooperation from the response being returned (unless the Martin Honnen nested iframe hack is used, about which more below).
location.replace()
rather than other means of setting/changing the iframe's source, to avoid putting the url on the browser's history (and hence affecting the back button and refresh).
The basic principle is straightforward and has been done many times before. However, the tricky implementation issues above are often not all dealt with, or are not dealt with well.
Furthermore, rampant confusion abounds which conflates iframe element objects, iframe window objects, and iframe document objects.
Some implementations that bear examination are listed below. I note here only some salient distinguishing characteristics, without detailing any criticisms.
Our approach is:
This is a cross-platform morass.
For getting an iframe window from the id or name attribute value of the iframe element:
var iframe_win = window.frames[nameval]Note that IE has both document.frames and window.frames; Moz has only window.frames.
var iframe_win = window.frames[idval]
var iframe_win = window.frames[index]A person could just assume that the last frame is the desired one:var iframe_win = window.frames[window.frames.length - 1]
To get the element given the id or name attribute value:
var iframe_el = document.getElementById(idval);(IE4+ has document.all[idval] and document.all[nameval], with document.all[nameval] being an Array if there are multiple ones.)
var iframe_el = document.getElementsByName(nameval)[0](recall that IE considers both ID and NAME for getElementsByName, and according to PPK http://www.xs4all.nl/~ppk/js/version5oud.html it doesn't cover all elements. Moz and W3 cover all elements, and consider only name.)
var iframe_el = document.getElementsByTagName('IFRAME')[index]PPK says getElementsByTagName does not work on IE5 PC: http://www.xs4all.nl/~ppk/js/version5oud.html
For going from iframe element to iframe window, see burst.xml.HtmlUtil.iframeContentWindow(iframe_el).
For going from iframe element to iframe document, see burst.xml.HtmlUtil.iframeContentDocument(iframe_el).
Public Member Functions | |
IframeURIRequest (Node iframe_el) | |
Construct a wrapper object around an iframe Node channel. | |
Static Public Member Functions | |
IframeURIRequest | getInstance () |
Class method to get an instance. | |
Protected Member Functions | |
void | destroy () |
remove the iframe Element from its parent Node, and eliminate any pointers we have. | |
Static Protected Member Functions | |
void | register (BU_IframeURIRequest instance) |
Registers the just-created BU_IframeURIRequest instance in the global registry. | |
BU_IframeURIRequest | acquire () |
Reconstitute an instance from the pool. | |
void | release (BU_IframeURIRequest instance) |
Class method called when load callbacks are done. |
|
Construct a wrapper object around an iframe Node channel. You generally want to call the class method getInstance() instead of the constructor directly, so that you can take advantage of instance pooling. If you happen to already have an iframe element on the page that is intended to be used for communication, that may be provided. The actual iframe element is created only on demand; it may already have one if this instance came from the pool. Any constructed object is automatically added to the pool whenever it is done being used. All instances have a state variable which is one of:
(This mimics microsoft readyState: http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/readystate_1.asp except for the addition of 'deleted').
|
|
Reconstitute an instance from the pool. If none are available returns a false value. Sets state from 'deleted' to 'uninitialized'. |
|
remove the iframe Element from its parent Node, and eliminate any pointers we have. used if we are doing pooling. |
|
Class method to get an instance. This is preferable to calling the constructor directly. |
|
Class method called when load callbacks are done. Sets state to 'deleted'. |