How to make the page automatically refresh once when it is opened _ basic knowledge-js tutorial

Source: Internet
Author: User
My webpage has a lot of images, and the server is not very good. Therefore, one or two images cannot be displayed after each page is opened, but all images can be displayed after the page is refreshed, I believe everyone has encountered this problem. Next we will introduce the solution in detail. The Code is as follows:


Script
Function window. onload (){
If (location. href. indexOf ('# reloaded') =-1 ){
Location. href = location. href + "# reloaded"
Location. reload ()
}
}
Script


-----------------------------------------------------------------------------
My webpage has a lot of images, and the server is not very good. Therefore, one or two images cannot be displayed after each page is opened, but they can all be displayed after being refreshed.

I don't want anyone browsing the page to click the "refresh" button every time. How can I add some code to the page so that the page will be automatically refreshed once it is opened?
---------------------------------------------------------------
Add the following code Between

---------------------------------------------------------------
Three methods:
1. script

The Code is as follows:


Function refreshPage (the_duration)
{
SetTimeout ("self. location. reload ();", the_duration * 1000 );
}
Self. onload = function (){
RefreshPage (1); // The value 1 indicates the interval of 1 second and not refreshed. You can change it to the one you want.
};
Script


2.
3.
Refresh only once:

---------------------------------------------------------------
It's late. The upstairs brother is right.
---------------------------------------------------------------
The above method is to refresh every five seconds, which puts a lot of pressure on the server. If a large number of requests are connected and the server is not very good, it is likely to become the server's host.
Therefore, a better method is to use Javascript. After loading, refresh the page with the following code:

The Code is as follows:


Related Article

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.