1

When user leaves page where plays youtube video playback is not stops. How can I solve it?

Thanks!

  • Sounds like you need to check out the [Page Visiblity API](http://www.w3.org/TR/2011/WD-page-visibility-20110602/), also mentioned in [this SO post](http://stackoverflow.com/questions/1060008/is-there-a-way-to-detect-if-a-browser-window-is-not-currently-active) Webdesigner Magazine had an example of exaclty this API using it to do exactly what you were looking for. Pause video when tab is changed, etc.. If you get an example started using that API, feel free to post any code you are having issue with. – Nope Jan 24 '13 at 14:07
  • Thank you for that information. It's very interesting for me. But it not solve my problem, because my problem not with browser tabs. I mean jquery mobile pages, which loads dinamically by ajax. – Stanislau Ladutska Jan 24 '13 at 14:19
  • Ah, I see, I overlooked the mobile tag. Glad you got it sorted wither way though. – Nope Jan 24 '13 at 16:23

1 Answers1

1
$(document).live('pagebeforehide', function(){
    player.pauseVideo();
});

This will tell the video to pause each time a new page is called.

Selven
  • 276
  • 4
  • 12
  • 1
    @StanislauLadutska: If you happen to use 1.7 or later, as said, `live()` was deprecated in 1.7 and completly removed in 1.9. Use `on()` as recommended in the documentation. Methods like `bind()` use `on()` anyway since 1.7 and beyond behind the scenes as seen in the 1.7.1 source: `bind: function( types, data, fn ) { return this.on( types, null, data, fn ); },` Might as well use `on()` then in the first place. – Nope Jan 24 '13 at 16:28
  • How do i get 'player' instance in jquery mobile ? – joshua Feb 14 '13 at 19:46