nepulgh

当页面完全加载完成后执行一个JS函数

方法1.如下程序,当页面完全加载后执行openTheIndexPage()方法  
<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
<title>Telecommunications Data Collection System</title>  
<script type="text/javascript" src="<%=contextPath%>/js/baseframe.js"></script>  
<script type="text/javascript" src="<%=contextPath%>/js/cookies.js"></script>  
<script type="text/javascript" src="<%=contextPath%>/js/tag/tag.js"></script>  
<script language="javascript" for="window" event="onload">   
    function openTheIndexPage() {       
        openMyURIWithCid(true, \'root\', \'IDX\', "iframe/dispatch.jsp?url=tdc/zhk/impctrlobjinf/index/index.jsp", \'首页\',  
                \'top.tagmenu\', \'top.maintop\', true,  
                \'system/accessPaths.do?currentModuleCode=IDX\',  
                \'mainmenu\', true);  
    };  
    if(document.readyState=="complete"){  
        openTheIndexPage();  
    }   
</script>  
</head>   
<body>   
</body>      
</html>  
方法2:可以是以下几种,但是效果不如方法1.   
<body onload="function name()"> </body >   
<script>window.onload=function name </script>   
<script language="javascript" for="window" event="onload">function name(); </script>   
第二种只能写入一个函数,而且无法给变量,其中最好用的是最后一种,可以独立写出来,怎么写都行。  
方法3:<body onload="xxx()"> </body> xxx()为你要执行的函数  
方法4:在script标记里加defer   
即 <script defer="defer" language="javascript">   
或者 <script defer language="javascript">   
在整个页面加载完后运行脚本。(没有效果)  

分类:

技术点:

相关文章:

  • 2021-11-18
  • 2021-11-29
  • 2021-11-29
  • 2021-11-29
  • 2021-11-28
  • 2021-11-18
  • 2021-11-29
  • 2021-12-15
猜你喜欢
  • 2021-11-03
  • 2021-11-18
  • 2021-11-18
  • 2021-11-18
  • 2021-11-01
  • 2021-11-18
  • 2021-11-18
相关资源
相似解决方案