Home

# Class goog.net.IframeIo

Class for managing requests via iFrames.

extends goog.events.EventTarget

Instance Method Summary
| `abort(?goog.net.ErrorCode= opt_failureCode)` Abort the current Iframe request
| `appendIframe_()` Appends the Iframe to the document body.
| `createIframe_()` Creates an iframe to be used with a request. We use a new iframe for each request so that requests don't create history entries.
| `disposeForm_()` Disposes of the Form. Since IE6 leaks form nodes, this just cleans up the DOM and nullifies the instances reference so the form can be used for another request.
| `disposeIframes_()` Disposes any iframes.

`disposeInternal()`

Unattach listeners from this object. Classes that extend EventTarget may need to override this method in order to remove references to DOM Elements and additional listeners, it should be something like this:

    MyClass.prototype.disposeInternal = function() {
    MyClass.superClass_.disposeInternal.call(this);
    // Dispose logic for MyClass
    };

| `getContentDocument_() ⇒ ?HTMLDocument`
| `getErrorChecker() ⇒ ?Function` Gets the callback function used to check if a loaded IFrame is in an error state.
| `getLastCustomError() ⇒ ?Object` Gets the last custom error.
| `getLastError() ⇒ string` Gets the last error message.
| `getLastErrorCode() ⇒ ?goog.net.ErrorCode` Gets the last error code.
| `getLastUri() ⇒ ?goog.Uri` Get the uri of the last request.
| `getRequestIframe_() ⇒ ?HTMLIFrameElement`
| `getResponseHtml() ⇒ ?string` Returns the last response html (i.e. the innerHtml of the iframe).
| `getResponseJson() ⇒ ?Object` Parses the content as JSON. This is a safe parse and may throw an error if the response is malformed. Use goog.json.unsafeparse(this.getResponseText()) if you are sure of the state of the returned content.
| `getResponseText() ⇒ ?string` Returns the last response text (i.e. the text content of the iframe). Assumes plain text!
| `getResponseXml() ⇒ ?HTMLDocument` Returns the document object from the last request. Not truely XML, but used to mirror the XhrIo interface.
| `getTimeoutInterval() ⇒ number` Returns the number of milliseconds after which an incomplete request will be aborted, or 0 if no timeout is set.
| `handleError_(?goog.net.ErrorCode errorCode, ?Object= opt_customError)` Handles errors.
| `handleIncrementalData_(?Object data)` Dispatches an event indicating that the IframeIo instance has received a data packet via incremental loading. The event object has a 'data' member.
| `handleLoad_(?HTMLDocument contentDocument)` Handles generic post-load
| `isActive() ⇒ boolean`
| `isComplete() ⇒ boolean`
| `isSuccess() ⇒ boolean`
| `makeReady_()` Finalizes the request, schedules the iframe for disposal, and maybe disposes the form.
| `onIeReadyStateChange_(?goog.events.BrowserEvent e)` Handles the load event of the iframe for IE, determines if the request was successful or not, handles clean up and dispatching of appropriate events.
| `onIframeLoaded_(?goog.events.BrowserEvent e)` Handles the load event of the iframe for non-IE browsers.
| `scheduleIframeDisposal_()` Schedules an iframe for disposal, async. We can't remove the iframes in the same execution context as the response, otherwise some versions of Firefox will not detect that the response has correctly finished and the loading bar will stay active forever.

`send((goog.Uri|null|string) uri, string= opt_method, boolean= opt_noCache, (Object|goog.structs.Map|null=) opt_data)`

Sends a request via an iframe. A HTML form is used and submitted to the iframe, this simplifies the difference between GET and POST requests. The iframe needs to be created and destroyed for each request otherwise the request will contribute to the history stack. sendFromForm does some clever trickery (thanks jlim) in non-IE browsers to stop a history entry being added for POST requests.

| `sendFormInternal_()` Submits the internal form to the iframe.

`sendFromForm(?HTMLFormElement form, string= opt_uri, boolean= opt_noCache)`

Sends the data stored in an existing form to the server. The HTTP method should be specified on the form, the action can also be specified but can be overridden by the optional URI param. This can be used in conjunction will a file-upload input to upload a file in the background without affecting history. Example form:

    <form action="/server/" enctype="multipart/form-data" method="POST">
    <input name="userfile" type="file">
    </form>

| `setErrorChecker(?Function fn)` Sets the callback function used to check if a loaded IFrame is in an error state.
| `setTimeoutInterval(number ms)` Sets the number of milliseconds after which an incomplete request will be aborted and a {@link goog.net.EventType.TIMEOUT} event raised; 0 means no timeout is set.
| `testForFirefoxSilentError_()` Tests for a silent failure by firefox that can occur when the connection is reset by the server or is made to an illegal URL.

Static Method Summary
| `addFormInputs_(?HTMLFormElement form, (Object|goog.Uri.QueryData|goog.structs.Map|null) data)` Adds the key value pairs from a map like data structure to a form
| `getForm_() ⇒ ?HTMLFormElement` Gets a static form, one for all instances of IframeIo since IE6 leaks form nodes that are created/removed from the document.
| `getIframeByName(string fname) ⇒ ?HTMLIFrameElement` Find an iframe by name (assumes the context is goog.global since that is where IframeIo's iframes are kept).
| `getInstanceByName(string fname) ⇒ ?goog.net.IframeIo` Find an instance of the IframeIo object by name.
| `getNextName_() ⇒ string`
| `handleIncrementalData(?Window win, ?Object data)` Handles incremental data and routes it to the correct iframeIo instance. The HTML page requested by the IframeIo instance should contain script blocks that call an externed reference to this method.
| `send((goog.Uri|null|string) uri, ?Function= opt_callback, string= opt_method, boolean= opt_noCache, (Object|goog.structs.Map|null=) opt_data)` Static send that creates a short lived instance of IframeIo to send the request.