A few days ago I asked here about how to add src attribute to iframe using jQuery. I actually got a code but it’s not working. I have just started studying jQuery so maybe, I thought, there was something I missed. Now I got a code that’s working, but the problem is when I close the lightbox, the video on the iframe continues streaming… How do I fix it? Here’s my current code:
$("#presentation").click(function(){
$("#iframe-presenter").get(0).contentWindow.location.href ='example.com';
});
$(".Close").click(function(){
$("#iframe-presenter").get(0).contentWindow.location.href = '#';
});
I am thinking of refreshing the page in the event of closing the lightbox, but I think it’s too distractive. Any help pls?…
UPDATE:
Ok so this one works:
$("#iframe-presenter").remove();
However, when relaunching the lightbox no video will appear since the code snippet above removes the iframe wich is #iframe-presenter. My solution now is:
$('.Close').after('<iframe id="iframe-presenter" src="example.com"></iframe>');
As you can see, jQuery now creates the iframe markup instead of HTML. So when I close the lightbox, it would still be able to load the iframe. But, it seems to load two streams at the same time even on first launch?
UPDATE 2:
Solved. .Close is a class so I made an ID for it…
try:
or