popup window with a video in browser

3

I am developing a web page and there is a request that I have from the client and I do not know how to carry it out.

My idea is that as soon as you enter the index, a video appears in a pop-up window (advertising) and when this video ends, the window disappears.

Is there any way to do it? and to control when the video ends?

The idea would be through a JavaScript script, but I'm not entirely clear about it.

Thank you.

EDIT:

With the help of Jordi Flores it's almost there:

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<style type="text/css">
#myVideo {
  display: none;
}
</style>

<!-- Add jQuery library -->
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>

<!-- Add mousewheel plugin (this is optional) -->
<script type="text/javascript" src="http://fancyapps.com/fancybox/lib/jquery.mousewheel-3.0.6.pack.js"></script>

<!-- Add fancyBox -->
<link rel="stylesheet" href="http://fancyapps.com/fancybox/source/jquery.fancybox.css?v=2.1.5" type="text/css" media="screen" />
<script type="text/javascript" src="http://fancyapps.com/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>



<script type="text/javascript">
$(document).ready(function() 
        {
$("#openVideo").fancybox({
 'closeBtn':false,
 'openEffect': 'fade',
 helpers   : { 
overlay : {closeClick: false} // prevents closing when clicking OUTSIDE fancybox 
}
});

//simulamos click y abrimos fancybox
$("#openVideo").eq(0).trigger("click");

//forzamos play
document.getElementById('myvideo').play();      
});

document.getElementById('myvideo').addEventListener('ended',myHandler, false);
function myHandler(e) {
console.log("el video se ha acabado!!")
$.fancybox.close();
}

</script>


</head>
<body>




<!--Boton para abrir video, solo para test  -->
<a href="#myVideo" id="openVideo">open video</a>

<div id="myVideo" >
   <div id="videoWrapper">
      <video id="myvideo" autoplay>
           <source src="008.mp4" type="video/mp4">
            Your browser does not support html5 videos
      </video>
   </div>
</div>





</body>
</html>

Although now the video does not close and if I put one located on my pc it does not play it.

    
asked by Sergio Cv 27.10.2016 в 13:18
source

3 answers

3

Here you can see a complete example:

use fancybox to open and encapsulate the video until it ends, once it has finished, with the event in js that you have in the example, you close the fancybox.

$(document).ready(function() 
                  {
		 $("#openVideo").fancybox({
           'closeBtn':false,
           'openEffect': 'fade',
           helpers   : { 
   overlay : {closeClick: false} // prevents closing when clicking OUTSIDE fancybox 
  }
         });
        
        //simulamos click y abrimos fancybox
        $("#openVideo").eq(0).trigger("click");
  
        //forzamos play
        document.getElementById('myvideo').play();      
	});

document.getElementById('myvideo').addEventListener('ended',myHandler, false);
    function myHandler(e) {
     console.log("el video se ha acabado!!")
     $.fancybox.close();
    }
#myVideo {
  display: none;
}
<!-- Add jQuery library -->
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>

<!-- Add mousewheel plugin (this is optional) -->
<script type="text/javascript" src="http://fancyapps.com/fancybox/lib/jquery.mousewheel-3.0.6.pack.js"></script>

<!-- Add fancyBox -->
<link rel="stylesheet" href="http://fancyapps.com/fancybox/source/jquery.fancybox.css?v=2.1.5" type="text/css" media="screen" />
<script type="text/javascript" src="http://fancyapps.com/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


<!--Boton para abrir video, solo para test  -->
<a href="#myVideo" id="openVideo">open video</a>

<div id="myVideo" >
   <div id="videoWrapper">
      <video id="myvideo" autoplay>
           <source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
           <source src="http://www.w3schools.com/html/mov_bbb.ogg" type="video/ogg">
            Your browser does not support html5 videos
      </video>
   </div>
</div>
    
answered by 27.10.2016 / 15:50
source
2

I have found several answers that may be useful to you, all with I've tried to develop the best I could, but I have not finished leaving it "nice". I hope someone edits it, or when I get home I'll do it from the computer better.

To create the PopUp
First Example ← StackOverflow English
Second Example

To insert a video with Html5
w3Schools with examples

.box {
  width: 20%;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.2);
  padding: 35px;
  border: 2px solid #fff;
  border-radius: 20px/50px;
  background-clip: padding-box;
  text-align: center;
}
.overlay {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
  transition: opacity 500ms;
  visibility: visible;
  opacity: 1;
}
.overlay:target {
  visibility: visible;
  opacity: 1;
  background-color: rgba(0, 0, 0, 0.8);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  z-index: 999;
  -webkit-transition: all 1s;
  -moz-transition: all 1s;
  transition: all 1s;
}
.popup {
  background-color: rgba(0, 0, 0, 0.8);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  /* Animación que durará 2 segundos*/
  -webkit-animation: autopopup 2s;
  -moz-animation: autopopup 2s;
  animation: autopopup 2s;
}
.popup h2 {
  margin-top: 0;
  color: #333;
  font-family: Tahoma, Arial, sans-serif;
}
.popup .close {
  position: absolute;
  top: 20px;
  right: 30px;
  transition: all 200ms;
  font-size: 30px;
  font-weight: bold;
  text-decoration: none;
  color: #333;
}
.popup .close:hover {
  color: orange;
}
.popup .content {
  position: relative;
  margin: 7% auto;
  padding: 30px 50px;
  background-color: #fafafa;
  color: #333;
  border-radius: 3px;
  width: 50%;
}
a.popup-cerrar {
  position: absolute;
  top: 3px;
  right: 3px;
  background-color: #333;
  padding: 7px 10px;
  font-size: 20px;
  text-decoration: none;
  line-height: 1;
  color: #fff;
}
to {
  opacity: 1;
}
}
@keyframes autopopup {
  from {
    opacity: 0;
    margin-top: -200px;
  }
  to {
    opacity: 1;
  }
}
<html>

<body>
  <div class="popup1" class="overlay">
    <div class="popup">
      <video width="320" height="240" controls>
        <a class="close" href="#popup1">X</a>
        <source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
          Your browser does not support the video tag.
      </video>
    </div>
  </div>


</body>

</html>
    
answered by 27.10.2016 в 13:53
1

In the OnLoad event of the index you have to open a page ( window.open(); ) where the video is and then play it

var video = document.getElementById("video");   
video.load();
video.play(); 

And for it to close you have to detect when it has just played, with an event:

video.addEventListener('ended',myHandler,false);
    function myHandler(e) {
        window.close();
    }
    
answered by 27.10.2016 в 13:29