JS Delay Load Speed page Open Speed sample code _javascript tips

Source: Internet
Author: User
First, JS delay loading

The code is as follows:
Copy Code code as follows:

<script language= "JavaScript" src= "id=" my "></script>
<script language= "JavaScript" >
settimeout ("document.getElementById" (' my '). src= ' include/... File ... php '; ", 3000);/delay 3 seconds
</script>

Second, JS finally loaded

Insert the following code where you want to insert JS:

<span id=l4ever>loading...</span>

Of course, that loading ... You can switch to your favorite small picture. It looks like an Ajax effect.

Then insert at the bottom of the page:
Copy Code code as follows:

<span Class=spanclass id=ad_l4ever>
Your JS code is here!</span>.
<script>L4EVER.innerHTML=AD_L4EVER.innerHTML; Ad_l4ever.innerhtml= "";</script>

Third, JS finally loaded

Want to show the location of the ad
<div id= "GUANGG1" ></div>

The content of the advertisement you want to display
Copy Code code as follows:

<div id= "Ggad1" style= "Display:none" >
<script language= "javascript" src= "/include/.......js" ></script>
</div>

Determine if there is an ad location to display
Copy Code code as follows:

<script language= "JavaScript" >
function Chkdiv (divid) {
var Chkid=document.getelementbyid (divID);
if (Chkid!= null)
{return true;}
Else
{return false;}
The last thing is to show the ads.
if (Chkdiv (' Guangg1 ')) {
document.getElementById (' Guangg1 '). Innerhtml= document.getElementById (' Ggad1 '). InnerHTML;
document.getElementById (' Ggad1 '). innerhtml= "";
}
</script>

SetTimeout usage

The standard syntax for settimeout is: settimeout (expression, time (milliseconds)) two parameters.

Here you'll note that the first parameter is called when a function is invoked, assuming that it is a functional.

1. Function No parameters:

function Alertv () {alert ("000");}

Delay one second when the first argument is not quoted ("" or "):
SetTimeout (alertv,1000);

Delay one second when the first argument is quoted again:
SetTimeout ("Alertv ()", 1000);

2. The function has the parameter:

function Alertv (event) {alert ("keycode=" +event.keycode);}

This should be set to:
settimeout (function () {ALERTV (event);},1000); Otherwise, you will be prompted for undefined parameters.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.