How to make the page automatically refresh once when it is opened so that all pictures can be displayed_Basic knowledge
- WBOYOriginal
- 2016-05-16 17:46:2218519browse
<script> <br>function window.onload(){ <br>if(location.href.indexOf('#reloaded')==-1){ <br>location.href=location.href "#reloaded" <br>location.reload() <br>} <br> } <br></script>
------------- -------------------------------------------------- -------------
My webpage has a lot of pictures, and the server is not very good, so every time I open the webpage, there are always one or two pictures that cannot be displayed, but after refreshing it, All can be displayed again.
I don’t want people to click the “refresh” button every time they browse the webpage. How can I add some code to the webpage so that it will automatically refresh after it is opened?
-------------------------------------------------- ----------------
Add the following code between
------------------------------------------------ ------------------
Three methods:
1.<script> <br><div class="codetitle">
<span><a style="CURSOR: pointer" data="96828" class="copybut" id="copybut96828" onclick="doCopy('code96828')"><u>Copy code</u></a></span> The code is as follows:</div>
<div class="codebody" id="code96828"> <br>function refreshPage(the_duration) <br>{ <br>setTimeout("self.location.reload(); ",the_duration*1000); <br>} <br>self.onload=function(){ <br>refreshPage(1);//The 1 inside represents 1 second, the interval between refreshes, you can change it to your Wanted<br>}; <br></script>
2.
3.
Refresh only once:
---- -------------------------------------------------- ----------
I'm late, the brother upstairs is right
------------------------- ---------------------------------------------
The method upstairs is every 5 It needs to be refreshed every second, which puts a lot of pressure on the server. If there are a large number of request connections and the server is not very good, it is likely to cause the server to crash.
So a better way is to use Javascript to implement it. To refresh after loading, just use the following code:
This is to re-request the server regardless of the cache of this page. .
setTimeOut refreshes this page after 1 second.
Put the above code between , calculate it as 1000×n and refresh it after n seconds, replacing 1000;
Try it out.
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn