I've been trying to figure out how to stop the audio from playing after closing a modal, and nothing seems to work.
My attempt
<script>
var docReadyCodeForModal = setInterval(function() {
if(jQuery) {
clearInterval(docReadyCodeForModal);
$("#myModal").modal('show');
$("#stopClose").click(function(){
$("#myModal").modal('pause');
});
}
}, 100);
</script>
<div aria-hidden="true" class="fade modal" id="myModal" style="display:none">
<div class="modal-lg modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" style="text-align:center">WELCOME TO THE THUNDERDOME!!!</h5>
<button id="stopClose" class="close" data-dismiss="modal" type="button">×</button></div>
<div class="modal-body">
<div class="embed-responsive embed-responsive-16by9"><iframe class="embed-responsive-item video-not-resize" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" src="https://www.youtube.com/embed/yGwjyodRst4?autoplay=1" title="YouTube video player"></iframe></div>
</div>
</div>
</div>
</div>
Note: video link removed for privacy reasons.
I appreciate any insight into this issue
Script to stop the video from playing when closing modal
Add an id to your iframe and replace #iframe-id with that id.
$(document).ready(function(){
var url = $("#iframe-id").attr('src');
$("#myModal").on('hide.bs.modal', function(){
$("#iframe-id").attr('src', '');
});
$("#myModal").on('show.bs.modal', function(){
$("#iframe-id").attr('src', url);
});
});
You are using Bootstrap. This script listens to the Bootstrap events when hiding and showing the modal.
It removes the url from the iframe src attribute when closing modal and adds the url when the modal its opened.
Related
I have a function where onclick, I want the iframe to append to another div within my website. So when the user clicks 'watch-youtube-video', this will then grab the iframe from 'youtube-video' and append just the src to the 'fixed-player' iframe src.
I have tried using the below jQuery but I am hitting an error. Could anyone please help?
HTML
<div class="fixed-player"><iframe src=""></div>
<div class="span-row wow scale-anm all animated">
<div class="portal-img ">
<div class="youtube-video">
<iframe frameborder="0" height="100%" width="100%" src="https://youtube.com/embed/10zsTgv8MxA?autoplay=1&mute=1&controls=0&showinfo=0&autohide=1&loop=1" allowautoplay="" allowfullscreen="" data-origwidth="100%" data-origheight="100%" style="width: 0px;">
</iframe>
</div>
</div>
<div class="portal-cont ">
<div class="top-cont ">
<div class="main-button grey-btn watch-youtube-video">
Watch Video
</div>
</div>
</div>
</div>
jQuery
$('.watch-youtube-video').on('click', function(){
$('.overlay').fadeIn();
$('.youtube-viewer-pop').fadeIn();
$(this).parent().parent().parent().find("iframe").attr("src").appendTo('fixed-player');
});
To set the src attribute of a jQuery object, you should be using the .attr() method instead, i.e.: .attr('src', <SOURCE>) instead:
const src = $(this).parent().parent().parent().find("iframe")[0].src;
$('.fixed-player').attr('src', src);
I am trying to embed an Iframe into a ngb-carousel. the carousel is showing up fine, the iframe "tab" is not:
<ngb-carousel *ngIf="project.images">
<ng-template class="item" ngbSlide *ngFor="let image of project.images">
<img class="img-fluid" [src]="image" alt="">
</ng-template>
<ng-template class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="project.video"></iframe>
</ng-template>
</ngb-carousel>
edit
stackblitz: https://stackblitz.com/edit/angular-xcmhun
You're missing the ngbSlide directive from the second ng-template in your example above. I edited your stackblitz example, adding that directive to the third ng-template in that example, and the embedded video shows up on a third tab as expected.
Forked example showing the solution: https://angular-ztaxde.stackblitz.io
yes please add ngbSlide:
<ngb-carousel>
<ng-template ngbSlide>
<iframe width="500" height="315" src="https://www.youtube.com/embed/J2qDRJdTGow" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</ng-template>
</ngb-carousel>
I have the following code. My button works fine, however I cant figure out how you make the function work.
My goal is to create a button that when clicked opens up the iframe for a youtube video/makes it visible.
<body>
<div class="bgimg w3-display-container w3-animate-opacity w3-text-white">
<div class="w3-display-middle">
<h1 class="w3-jumbo w3-animate-top">TAKE YOUR MARK</h1>
<hr class="w3-border-grey" style="margin:auto;width:40%">
<p><button class="w3-center center transparent_btn"
onclick="play1()">go</button></p>
</div>
</div>
</body>
<script>
function play1() {
<iframe width="560" height="315" src="https://www.youtube.com/embed/AkFs3YzxN_E" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
}
You need to have an element that the iframe can be inserted into.
<body>
<div class="bgimg w3-display-container w3-animate-opacity w3-text-white">
<div class="w3-display-middle">
<h1 class="w3-jumbo w3-animate-top">TAKE YOUR MARK</h1>
<hr class="w3-border-grey" style="margin:auto;width:40%">
<p><button class="w3-center center transparent_btn"
onclick="play1()">go</button></p>
<div id="youtube-frame"></div>
</div>
</div>
</body>
<script>
function play1() {
var frame = document.getElementById("youtube-frame");
frame.innerHTML += "<iframe width='560' height='315' src='https://www.youtube.com/embed/AkFs3YzxN_E' frameborder='0' allow='accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture' allowfullscreen></iframe>";
}
</script>
Although youtube offers an API to control the player, but I'll keep things simple.
First, add a div inside your body and give it an ID of your choice.
Your play1() function should be like this:
function play1(){
var player = '<iframe width="560" height="315"
src="https://www.youtube.com/embed/AkFs3YzxN_E" frameborder="0"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-
picture" allowfullscreen></iframe>';
document.getElementById('ID').innerHtml = player;
}
I am trying to embed a video in the HTML page, however, the iframe is being blocked. I am not an expert with HTML. I can insert the video through object Can you please suggest what could be the issue ?
<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<button class="closeButton" aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
<iframe allowfullscreen="" src="http://player.vimeo.com/video/15731659" frameborder="0" width="880" height="450"></iframe>
</div>
</div>
</div> <!-- /.modal -->
This is the syntax for embed.
<embed src="helloworld.flv">
In case of embedding youtube video
<iframe width="560" height="315" src="//www.youtube.com/embed/0SU8-HJtYYc" frameborder="0" allowfullscreen></iframe>
Don't try iframe, as it will load two pages at a same time. Which may cause slow execution.
Here is the w3schools link : http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_embed_src
Can we make the following Google Map interactive provided the frame image is showing.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<input type="button" onclick="$('#frame_image').show();" value="Show frame layer">
<input type="button" onclick="$('#frame_image').hide();" value="Hide frame layer">
<br /><br />
<div style="position: absolute; z-index: 1;">
<iframe frameborder="0" width="358" height="358" marginheight="0" marginwidth="0" scrolling="no" src="https://maps.google.ca/maps?f=q&source=s_q&hl=en&geocode=&q=55+Avenue+Road,++Toronto,+Ontario+M5R+3L2+Canada&aq=&sll=43.656877,-79.32085&sspn=0.852471,2.113495&ie=UTF8&hq=&hnear=55+Avenue+Rd,+Toronto,+Ontario+M5R+1C6&t=m&z=14&ll=43.67111,-79.395217&output=embed&iwloc=near" ></iframe> <br />
<small>View Larger Map</small>
</div>
<div style="position: absolute; color:red; z-index: 2" id="frame_image">
<img src="http://torontoclinic.awkwardhosting.com/images/frame.gif" />
</div>
Code is also on the following link:
http://jsfiddle.net/pPrZV/
Please let me know if there is any other way via Google Maps API etc.
Thanks
Just apply this style to <iframe> of the google map
<iframe style="border-radius:250px" frameborder="0" width="358" height="358" marginheight="0" marginwidth="0" scrolling="no"...
Working jsFiddle here