question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resizing iframe with injected iframeResizer.contentWindow.min.js

See original GitHub issue

Hi,

I’m trying to resize a iframe which holds a static html page, but I don’t want to modify the page by hand.

So, I’m injecting the contentWindow.js by jQuery:

$(function () {
// ...

    (function () {
        const $iframe= $('.iframe');
        if ($iframe.length <= 0) {
            return;
        }

        $iframe.contents().find("head, body, div").first().append("<script src='https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/3.6.0/iframeResizer.contentWindow.min.js'></script>");
        $iframe.iFrameResize([{log: true}]);
    })();

// ...
});

However, the only output I get in the browser console is:

iframeResizer.js:132 [iFrameSizer][Host page: iFrameResizer0] IFrame has not responded within 5 seconds. Check iFrameResizer.contentWindow.js has been loaded in iFrame. This message can be ingored if everything is working, or you can set the warningTimeout option to a higher value or zero to suppress this warning.

So it seems that the contentWindow.js does not load correctly? Do I have to send some event?

PS: The script is injected correctly: image

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
auchricommented, Apr 25, 2018

Well, I think I found the answer:

https://stackoverflow.com/a/9777536

If I load the content from the .js file and inject it like

$.get('iframeResizer.contentWindow.min.js', function (data) {
    $head.append('<script>' + data + '<\/script>');
    $frame.iFrameResize({log: true});
});

, it works.

0reactions
davidjbradshawcommented, Apr 25, 2018

Glad you found a solution and I might build that in one day.

Read more comments on GitHub >

github_iconTop Results From Across the Web

iFrame Resizer - GitHub Pages
The package contains two minified JavaScript files in the js folder. The first (iframeResizer.min.js) is for the page hosting the iFrames. It can...
Read more >
Resizing an iframe based on content - Stack Overflow
How do I resize the iframes to fit the height of the iframes' content? I've tried to decipher the javascript Google uses but...
Read more >
Include iframe resizer inside embedded iframes | Community
On your side, this would only mean injecting the iframeResizer.contentWindow.min.js file in each report, and specify in your doc that the ...
Read more >
iframe-resizer | Yarn - Package Manager
Keep same and cross domain iFrames sized to their content with support for ... v4.3.2 #936 Allow max/min values for iFrame size to...
Read more >
How do I make my iframe resize to its content? - Wyng
The iframe resizer code enables your iframed campaign to automatically resize to the height and width of both ... contentWindow.min.js'; firstScriptTag.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found