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

Feature request: onLoaded option #36

Closed
SuperPat45 opened this issue Jan 30, 2020 · 3 comments
Closed

Feature request: onLoaded option #36

SuperPat45 opened this issue Jan 30, 2020 · 3 comments

Comments

@SuperPat45
Copy link

Please add an onLoaded option.
I need this to detect if the iframe initialized a download popup, in which case, the onLoaded option allow me to detect if data appear in iframe; and thus, I can close BigPicture

@henrygd
Copy link
Owner

henrygd commented Feb 10, 2020

Sorry, I'm a little overloaded at the moment w/ life things. I can probably add this and #35 this week.

As far as larger feature requests like #33, #37, #38, I'm planning to make a more feature rich spin off of this library from the ground up at some point, and new development time will likely go there instead of here. It should be fully backwards compatible. But I'd like to keep this one as slim as possible so people will continue to have that option (not that the new one is going to be massive -- but still).

@SuperPat45
Copy link
Author

Fine Thanks, #25 would be awesome too.

@henrygd
Copy link
Owner

henrygd commented Feb 15, 2020

Unfortunately it seems that iframes always trigger the load event even if there's an error. So we can't rely on onload / onerror to tell if the frame loaded successfully.

We would have to access the document, but that's blocked for all cross-origin frames. And because that's what users of this library will be loading 99% of the time, I feel like including error / load callbacks for iframes is going to confuse people.

However, if you're using a same-origin frame, you should still be able to get what you need using animationStart. See below. I'm going to close this and #35, but let me know if you have any questions. If you want to link me to a demo I'd be happy to look over it.

animationStart: function () {
	var iframe = document.querySelector('#bp_container iframe')
	iframe.addEventListener('load', function () {
		var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
		var iframeBody = iframeDoc.body;
		console.log('iframeBody', iframeBody);
	}, {once: true})
}

({once: true} is not supported in IE, so use a different method -- like storing whether the listener has been added previously, or manually removing the listener using onClose -- if you need to support it)

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

No branches or pull requests

2 participants