Skip to content

Instantly share code, notes, and snippets.

@angusdev
Created November 20, 2013 15:05
Show Gist options
  • Save angusdev/7564665 to your computer and use it in GitHub Desktop.
Save angusdev/7564665 to your computer and use it in GitHub Desktop.
How to trigger a custom event to a child iframe
// Parent Window
$('button').click(function(e) {
// This doesn't work
$('#container iframe').contents().find('body').trigger('myevent');
// This works
$('#container iframe').each(function(){
this.contentWindow.$('body').trigger('myevent');
});
});
// iframe
$(document).ready(function() {
$(document.body).bind('myevent', function(e) {
alert('myevent');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment