Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop a Vimeo video with jQuery

When I hide a YouTube video, it stops playing. However, this is not the case for Vimeo videos. Is there another way to stop a Vimeo video?

like image 374
Justin Meltzer Avatar asked May 26 '11 22:05

Justin Meltzer


People also ask

How to stop Vimeo video with jQuery?

If you use Vimeo's updated API code then you can do it like the following: http://jsfiddle.net/deshg/8CV2S/. You can see the stop button now gives you the alert and then the video is unloaded. Cheers!

How do I disable right click on Vimeo?

Then use the following: $( sibling element ). on("contextmenu", function(e) { return false; }); There is some extra styling involved as well, review the demo.


2 Answers

First, add an ID to your iFrame. Then add this to your javascript close window click function:

var $frame = $('iframe#yourIframeId');  // saves the current iframe source var vidsrc = $frame.attr('src');  // sets the source to nothing, stopping the video $frame.attr('src','');   // sets it back to the correct link so that it reloads immediately on the next window open $frame.attr('src', vidsrc); 
like image 147
Deborah Avatar answered Sep 21 '22 09:09

Deborah


I recently needed to pause a Vimeo video that was inside a Bootstrap modal when the modal was closed.

The Vimeo video was embedded in an iframe.

This is what worked for me:

$("#my-bootstrap-modal").on('hidden.bs.modal', function (e) {     var div = document.getElementById("my-bootstrap-modal");     var iframe = div.getElementsByTagName("iframe")[0].contentWindow;     iframe.postMessage('{"method":"pause"}', '*'); }); 
like image 40
johna Avatar answered Sep 21 '22 09:09

johna