Quit function on body onLoad

前端 未结 3 552
离开以前
离开以前 2021-01-26 22:40

I need a script thats redirects the user to a second side, when the mainpage need to long to load.

I did this:

 

        
相关标签:
3条回答
  • 2021-01-26 23:14
      setTimeout("location.replace('contact.html')",10000);
    

    Instead, you can try

      setTimeout(function(){window.location='contact.html'},10000);
    
    0 讨论(0)
  • 2021-01-26 23:30

    You Can try Following

    var Ispreloader=false;
    
        <script type='text/javascript'>   
            $(document).ready(function() {
             if(!Ispreloader)
             {
               myfunction();
              }
    
            });
    
    function myfunction()
    {
      setTimeout("location.replace('contact.html')",10000);
    }
    
    //------------Whenever preploadeer loads on bodu unload set the variable to true
    
    Ispreloader=true;
     </script>
    
    0 讨论(0)
  • 2021-01-26 23:32

    Try this:

    var redirect = setTimeout(function(){
                      window.location = 'somewhere'
                   }, 10000)
    
    $(document).ready(function() { // or $(window).load(function() {
        clearTimeout(redirect);
    });
    
    0 讨论(0)
提交回复
热议问题