tags:

views:

33

answers:

1

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...

+1  A: 

try:

$(".Close").click(function(){
      $("#iframe-presenter").get(0).contentWindow.remove()
});

or

$(".Close").click(function(){

     $("#iframe-presenter").get(0).contentWindow.location.href = 'javascript:;';

});
Christian Smorra
@Christian: Unfortunately, it doesn't work... :-(
Joann
I chose this though it doesn't really work. And I feel obligated to chose so my acceptance rate won't drop? The one that works is in my explanation above. But this is close and it gave me the idea.
Joann
care to elaborate? i'll try to help you if you let me know what the problem is now
Christian Smorra