How do I call a JavaScript function on page load?

后端 未结 8 1362
轮回少年
轮回少年 2020-11-22 15:18

Traditionally, to call a JavaScript function once the page has loaded, you\'d add an onload attribute to the body containing a bit of JavaScript (usually only c

8条回答
  •  抹茶落季
    2020-11-22 15:45

    here's the trick (works everywhere):

    r(function(){
    alert('DOM Ready!');
    });
    function r(f){/in/.test(document.readyState)?setTimeout('r('+f+')',9):f()}
    

提交回复
热议问题