Home > Web Front-end > JS Tutorial > body text

如何让页面在打开时自动刷新一次让图片全部显示_基础知识

WBOY
Release: 2016-05-16 17:46:22
Original
18449 people have browsed it
复制代码 代码如下:

<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>


-----------------------------------------------------------------------------
我的网页的图片较多,而服务器也不是很好,所以每次打开网页后总有一、两幅图片无法显示,但刷新一遍后又全部可显示了。

不想让浏览网页的人每次都点“刷新”按钮,请问如何在网页中加入一些代码,让网页在打开后又自动刷新一次?
---------------------------------------------------------------
把下面代码加在 之间

---------------------------------------------------------------
三种方法
1.<script> <BR><div class="codetitle"><span><a style="CURSOR: pointer" data="96828" class="copybut" id="copybut96828" onclick="doCopy('code96828')"><U>复制代码 代码如下:<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);//里面的1代表1秒,未刷新的间隔时间,你可以改成你想要的 <BR>}; <BR></script>

2.
3.
只刷新一次:

---------------------------------------------------------------
来晚了,楼上兄说的对
---------------------------------------------------------------
楼上这样的方法是每隔5秒钟就要刷新一次,对服务器的压力很大,如果在大量的请求连接以及服务器不是很好的情况下很可能变成服务器的当机。
所以比较好的办法是在用Javascript来实现。在装载完了以后刷新一下,只要用如下的代码:
复制代码 代码如下:



这个是在不管本页面的缓存情况下,向服务器重新请求一次。
setTimeOut 是在1秒钟以后刷新本页面。
把上面的代码放到 之间,以1000×n计算n秒以后刷新,替换1000;
试试看吧。
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!