Skip to content

Resize By Iframe #7

@tomas-sereikis

Description

@tomas-sereikis

Hi,

So i saw issue A method to support IE11 without having to rely on MutationObserver #2 and came up with idea of how to catch resize event, so what are your thoughts.

(function($) {
    var stylesCreated = false;
    var createStyles = function() {
        var style = $('style');
        style.text('.jq-custom-frame-resize{position:absolute;top:0;left:0;width:100%;height:100%;border:0;z-index:-1;background:transparent;}');
        $('head').append(style);
    };

    $.fn.elementResize = function(fn) {
        if (stylesCreated === false) {
            createStyles();
        }

        var onFrameResize = function() { window.onresize = document.resizeCallback; };

        var frame = document.createElement('iframe');
        frame.setAttribute('src', 'javascript:;');
        frame.className = 'jq-custom-frame-resize';
        this.append(frame);

        var script = frame.contentWindow.document.createElement('script');
        script.textContent = ['(', onFrameResize.toString(), ')();'].join('');
        frame.contentWindow.document.resizeCallback = fn;

        var style = document.createElement('style');
        style.type = 'text/css';
        style.textContent = 'body,head{height:100%} body{margin:0;padding:0;}';

        var head = frame.contentWindow.document.querySelector('head');
        head.appendChild(script);
        head.appendChild(style);
    };
})(jQuery);

it looks simpler it works so... why is your way better?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions