Copy code code as follows:
<script src = "../ cgi-bin/delscript.js" defer> </script>
The DEFER role is that the document is loaded before executing the script, so that the problem that can not be avoided cannot be found --- Some problems
<button id = "mybutton" onclight = "alert ('ok')"> test </Button>
<script>
mybutton.click ();
</script>
<script>
mybutton.click ();
</script>
<button id = "mybutton" onclight = "alert ('ok')"> test </Button>
<script defer>
Function document.body.onload () {
alert (document.body.Offsetheight);
}
</script>
Adding DEFER is equivalent to executing after the page is completely entered, which is equivalent to Window.onload, but it is more flexible than Window.onload!
DEFER is a "unknown hero" in the powerful function of the script program. It tells the browser's Script segment that contains code that does not need to be executed immediately, and it is combined with the SRC attributes. It can also make these scripts download in the background, and the content of the front desk is normally displayed to users.
-But the document is loaded and then executes the script
Please pay attention to two points in the end:
1. Do not call the document.write command in the DEFER script program segment, because the document.write will produce a direct output effect.
2. And, do not include any global variables or functions to be used immediately in the DEFER script program segment.
A commonly used optimization method is: when the script does not need to run immediately, set the "DEFER" property in the <script> tag. (Immediate script is not included in a Function block, so it will be executed during the loading process.) After setting the "DEFER" property, IE does not have to wait for the script to load and execute. This pages will be loaded faster. Generally speaking, this also indicates that the immediately script is best placed in the Function block and handles the function in the online handle of the Document or Body object. When some scripts need to rely on the user's operation, it is executed-for example, the click button, or the mouse to a certain area-it is very useful to use this attribute. However, when there are some scripts that need to be executed during the page loading or loading, the benefits of using the Defer attribute are not too great.
They are all caused by DEFER. In the past two days, the website views the full text error
<p style = 'line-height: 150%; text-indent: 15pt;'> Last weekend, Google ads on this site. Script> I used the Defer delay to import the advertisement. I have always used the Firefox browser. I haven't found a problem. Today, a friend went to this site to check the information. She used Maxthon. Tell me to check the article. It was over, and then I knew that there was a problem. I said that the interviews of such a website have been dropped in these two days. After checking the reason, I found that it was the reason for Defer, because the defer in Firfox seems to be invalid. The page is actually primitive. The content is loaded together, and in IE, due to the delayed loading script, for the Google AD script, it uses the method of writing document.write, and because of the DEFER reasons, the script detection of Google AD is iframe as iframe It is, so when the actual content of Google ads is obtained, the entire page is covered, which also causes the phenomenon of viewing the full text. </p>
<p style = 'line-height: 150%; text-indent: 15pt;'> This blame me to modify the code without testing. In the future, you need to test it in IE and Firefox regardless of everything. For these two Heavenly apology caused by everyone's interview difficulties! </p>
<p style = 'line-height: 150%; text-indent: 15pt;'> In addition: It is recommended that you use Firefox to access this site, accessing and parsing speed and page layout consistency! </p>