Multiple methods implement an js function when the jsp page is fully loaded
- 2020-06-15 10:05:17
- OfStack
Method 1: Perform the openTheIndexPage() method when the page is fully loaded
Method 2: It could be any of the following, but it's not as effective as method 1.
The second type can only write 1 function and cannot be assigned to variables, but the best one is the last one, which can be written independently, however you like.
Method 3: < body onload="xxx()" > < /body > xxx() is the function you want to execute
Method 4: Add defer to the script tag
namely < script defer="defer" language="javascript" >
or < script defer language="javascript" >
Run the script after the entire page has loaded. (No effect)
<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", ' Home page ',
'top.tagmenu', 'top.maintop', true,
'system/accessPaths.do?currentModuleCode=IDX',
'mainmenu', true);
};
if(document.readyState=="complete"){
openTheIndexPage();
}
</script>
</head>
<body>
</body>
</html>
Method 2: It could be any of the following, but it's not as effective as method 1.
<body onload="function name()"> </body >
<script>window.onload=function name </script>
<script language="javascript" for="window" event="onload">function name(); </script>
The second type can only write 1 function and cannot be assigned to variables, but the best one is the last one, which can be written independently, however you like.
Method 3: < body onload="xxx()" > < /body > xxx() is the function you want to execute
Method 4: Add defer to the script tag
namely < script defer="defer" language="javascript" >
or < script defer language="javascript" >
Run the script after the entire page has loaded. (No effect)