• Jump To … +
    breakpoints.js date-parse.js jquery.breakpoints.js jquery.calcRestrainedPos.js jquery.clientRect.js jquery.contentSize.js jquery.cookies.js jquery.css.js jquery.customEvent.js jquery.delimitedString.js jquery.disableEvent.js jquery.hostIframe.js jquery.hoverDelay.js jquery.htmlEncode.js jquery.imageSize.js jquery.isVisibleKeyCode.js jquery.menu.js jquery-menu-exampleskin.js jquery.modalDialog.deviceFixes.js jquery.modalDialog.getSettings.js jquery.modalDialog.header.js jquery.modalDialog.history.js jquery.modalDialog.js jquery.modalDialog.unobtrusive.js jquery.modalDialog.userAgent.js jquery.modalDialogContent.header.js jquery.modalDialogContent.js jquery.msAjax.js jquery.ns.js jquery.partialLoad.js jquery.postMessage.js jquery.proxyAll.js jquery.queryString.js jquery.richTooltip.js jquery.scrollAnchor.js jquery.uncomment.js jquery.url.js pointy.gestures.js pointy.js
  • jquery.hostIframe.js

  • ¶
    (function ($) {
        var DOCUMENT_NODE = 9;
  • ¶

    Gets a jQuery object containing the iframe element containing the current content

        $.fn.hostIframe = function () {
            return this.map(function (index, doc) {
  • ¶

    TODO make this work for windows too

                if (doc.nodeType != DOCUMENT_NODE) {
                    throw new Error("Element is not a document");
                }
    
                var win = doc.defaultView ? doc.defaultView : doc.parentWindow;
    
                try {
                    if (win && win.frameElement) {
                        return win.frameElement;
                    }
                } catch (e) {
  • ¶

    accessing win.frameElement might fail if iframe is cross-site

                }
    
                return null;
            });
        };
  • ¶

    If the current jQuery object contains an iframe, this gets a jQuery object containing the iframe’s document

        $.fn.iframeDocument = function () {
            return this.map(function (index, iframe) {
                try {
                    return iframe.contentWindow.document;
                } catch (ex) {
                    return null;
                }
            });
        };
  • ¶

    If the current jQuery object contains an iframe, this gets a jQuery object containing the iframe’s content window

        $.fn.iframeWindow = function () {
            return this.map(function (index, iframe) {
                return iframe.contentWindow;
            });
        };
    
    })(jQuery);