Cameron Cameron - 1 year ago 148
Javascript Question

VideoJS: Stopping video on modal close and not embedding in page

I have been using the JavaScript script VideoJS: to build some video players that can be shown to the user in a popup. I have built the popup as follows:

<script type="text/javascript">


jQuery(document).ready(function ()
// videos have video js applied to them

$(".show-video").click(function ()
$(".close-video").click(function ()


<a class="show-video">Show Video</a>

<div class="video-background">
<div class="video-container">

<div class="video-js-box vim-css">
<video id="video1" class="video-js" poster="wallpaper.png" controls="controls" width="1024" height="768">
<source src="video.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
<object id="flash_fallback_1" class="vjs-flash-fallback" width="1024" height="768" type="application/x-shockwave-flash"
<param name="movie" value="" />
<param name="allowfullscreen" value="true" />
<param name="flashvars" value='config={"playlist":["poster.png", {"url": "video.mp4","autoPlay":false,"autoBuffering":true}]}' />

<a class="close-video">Close Video</a>


I have two problems:

1) If the video is playing and the user closes the video popup, the video will still be playing in the background... how do I stop this?

2) I've noticed on sites like: that the videos popup in the same way by using a hashtag and id to show content but unlike in my example the video isn't in the page... any ideas on how they do this? As they arn't loading an external webpage. Would love to see some examples of how to do this with jQuery as I will be having multiple videos so would be great to just pull them in based on the hashtag on the link!


Answer Source

There are 2 ways you can do this.

  1. Remove the whole video when the popup is closed. Use $(video).remove()
  2. Use the videojs javascript method

      var myPlayer = VideoJS.setup("example_video_1");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download