0

i search for jquery page load.

I always face that people use something like that

jQuery("#popup").fadeIn(4000); //function to redirect the page after few seconds
                            window.location.replace("http://"+a_href);  
                        }, 3000)

They sets timeout 3000 .However, there is a possibilty that the page could not be loadded after 3 sec.

Is there a way to do this dynamically ?

snnlankrdsm
  • 1,401
  • 5
  • 19
  • 29

1 Answers1

1

You don't need to predict whether 3 seconds is long enough, you can simply use a callback function so that the element isn't faded back in until it has loaded.

Also, window.location.replace() won't load the content into the popup, it'll change the whole web page to this new location. Instead you should use jQuery Load ($.load()).

Therefore you don't need the fade animation to last for 3 seconds, you can have it animate as long/short as you like. In my example I've reduced this to 0.3 seconds.

Use the following instead:

var $popup = $("#popup");
$popup.fadeOut(300, function(){
   $popup.load("http://"+a_href, function(){
       $popup.fadeIn(300);
   });   
});
Community
  • 1
  • 1
Curtis
  • 101,612
  • 66
  • 270
  • 352