Terminating any connection after "closing" the link

0

To use a small ajax code to open some links! But sometimes these links have some videos !! And until it loads !! Only the problem is that these links are opened in a lightbox! And when you close the lightbox the video keeps rolling !! Which sucks! Because it actually only closes the lightbox! You do not "end" the link!

How do you perform this link "closure" as soon as you close lightbox?

Lightbox Script

$(document).ready(function() {
  $('.lightbox').click(function(){
      $('.background, .box').animate({'opacity':'.9'}, 1, 'linear');
      $('.box').animate({'opacity':'1.00'}, 1, 'linear');
          $('.background, .box').css('display','block');
   }); 

   $('.close').click(function(){
          $('.background, .box').animate({'opacity':'0'}, 1, 'linear', function(){
              $('.background, .box').css('display','none'); 
          });
    });
});

Ajax Code

  //Carregamento AJAX
  function pag(brl)
      {   
      var url = eval("brl");
      $( "#content" ).load(url, function(e) {
          e.preventDefault()
  });
      }

Link is like this :::

<a class="home lightbox" href="#!" onclick="pag('urlaseraerta.php');">link</a>
    
asked by anonymous 09.04.2015 / 03:11

1 answer

0

To figure out how to solve you have to figure out what happens when you click in the link and run the pag('urlaseraerta.php') function.

The $( "#content" ).load method of jQuery will fetch HTML from the url you passed as the function argument and insert this HTML into the element you used in the selector where you used the .load() method.

When you click to remove the link, what you are doing is hiding the element, only changing its visibility. That is, the content is still there, only without being visible to the user.

What you need to do is to empty this div for the content to disappear from the DOM. To do this, just add .html(''); that replaces the content with an empty string.

$('.close').click(function(){
      $('.background, .box').animate({'opacity':'0'}, 1, 'linear', function(){
          $('.background, .box').css('display','none').html('');
          //                                          ^   ^   ^ - juntei aqui o que faltava
      });
});
    
09.04.2015 / 08:12