How to show an alert after reloading the page in JavaScript?

前端 未结 5 920
栀梦
栀梦 2020-12-31 07:31

I am trying to make alert box after page reloaded, but it doesn\'t work.
Please correct my code and tell me why?

$(\"button\").click(function(){
    wind         


        
5条回答
  •  爱一瞬间的悲伤
    2020-12-31 08:25

    That's called onload. It came waaaaay before DOM ready was around, and DOM ready was actually created for the exact reason that onload waited on images.

    window.onload = function () { 
        alert("It's loaded!");
        //dom not only ready, but everything is loaded
    }
    

    And a jQuery Javascript solution is to bind the window.onload event in document.ready().

    $(window).bind("load", function() {
       // code here
    });
    

提交回复
热议问题