Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javascript error when iFrame removed by Angular. #160

Closed
nelisbijl opened this issue Mar 4, 2015 · 13 comments
Closed

Javascript error when iFrame removed by Angular. #160

nelisbijl opened this issue Mar 4, 2015 · 13 comments
Labels

Comments

@nelisbijl
Copy link

When I leave the page containing the iFrame (actually an angular ui-router ui-view), i get the error:

Unhandled exception at line 8, column 4217 in http://localhost:60049/vendor/iframe-resizer/js/iframeResizer.min.js

0x800a138f - JavaScript runtime error: Unable to get property 'postMessage' of undefined or null reference

Is it a bug? Is there any possibility to unbind/detach/unsubscribe before leaving the page?
You could test for iframe.contentWindow in the target method but it would be better if you could gracefully exit a page with an iFrame

@davidjbradshaw
Copy link
Owner

That's an interesting one. Would you be able to create a simple test case I could look at?

I guess Angular is removing the iFrame from the page whilst this code is running. I take a look in the next few days, if you want to have a play, look at the trigger function at line 408. I expect adding something like if(contentWindow in iframe){...} will fix this for you.

@davidjbradshaw
Copy link
Owner

Oh I just reread your post and see you also suggested that.

The code is very loosely bound to the html, and the trigger function only gets called in one of two ways, at page setup, or mid-way through a double page resize used to workout if the page needs to size downwards with some of the non-standard height calculation methods.

So I think doing check in the target function is the cleanest way of handling this.

@nelisbijl
Copy link
Author

After I worked around this issue the client side crashed on Math.max telling me that Math did not exist !?
I resolved things for now by calling close from the client side but that is of course non-ideal

@davidjbradshaw
Copy link
Owner

This gets stranger and stranger. The Math object is only used in the iFrame, not the parent page and then only to work out the height of the page. If you've removed the iFrame then this code can not be running.

To me it looks like the iFrame isn't being fully removed from the page by Angular. Have you tried removing it from the page directly, rather than calling the close() method in the child?

var iframe = document.getElementByTagname('iframe')[0];
iframe.parentNode.removeChild(iframe);

It's difficult for me to make any more suggestions without seeing an example of the problem.

@davidjbradshaw
Copy link
Owner

Closed due to no response.

@nelisbijl
Copy link
Author

Finally found the time to make an example:
https://jsfiddle.net/nelis/aznb65jL/16/

@davidjbradshaw
Copy link
Owner

The fiddle doesn't work due to JS location.

screen shot 2015-03-26 at 09 54 09

@nelisbijl
Copy link
Author

Weird, could you try Firefox

@markvantilburg
Copy link
Contributor

In firefox the errors do trigger. It seems safari is more strict about loading javascript files with the wrong mime-type

160-firebug

@davidjbradshaw
Copy link
Owner

This gets stranger and stranger. Will dig in more deeply when I get some time. Can you turn the log option on the fiddle please.

The problem is that the reset call gets received by the parent, but I don't see it being triggered in the iframe! In the mean time if change to the resize method to 'lowestElement' or 'grow' the problem goes away.

@nelisbijl
Copy link
Author

log: true -> https://jsfiddle.net/aznb65jL/20/

@davidjbradshaw
Copy link
Owner

I've just updated the version in src to warn rather than error in this situation. JSFiddle seems to do strange things with the log. Can you make a stand alone example I can look further at.

@davidjbradshaw davidjbradshaw changed the title Javascript error when navigating away from page containing iFrame Javascript error when iFrame removed by Angular. Apr 5, 2015
@davidjbradshaw
Copy link
Owner

This is now a warning, rather than an error in v2.8.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants