js脚本网站刷新就停止了(js禁止刷新当前页面)

http://www.itjxue.com  2023-02-03 18:14  来源:未知  点击次数: 

网页第一次加载 执行js 再次刷新就不执行 怎么实现

第一次加载执行js

刷新,实现是可以实现的,但是我不知道你要达到什么样的效果。如果说只写个普通的刷新页面的js话每次加载的时候都会触发这个刷新页面。就会死循环。我没碰到过这种情况,你可以将服务器短设置个变量放入session的作用域中判断如果这个变量为1就让js刷新,否则不刷新。不知道能不能提供一些帮助。。

java web开发,js自动刷新页面过一段时间后页面会崩溃,,,怎么办,,求助大神!!解决了给冲20话费~~

setInterval:

The real delay between func calls for setInterval is less than in the code!

That’s normal, because the time taken by func’s execution “consumes” a part of the interval.

It is possible that func’s execution turns out to be longer than we expected and takes more than 100ms.

In this case the engine waits for func to complete, then checks the scheduler and if the time is up, runs it again immediately.

In the edge case, if the function always executes longer than delay ms, then the calls will happen without a pause at all.

setTimeout:

The recursive setTimeout guarantees the fixed delay (here 100ms).

That’s because a new call is planned at the end of the previous one.

举例:

JS控制网页自动刷新,如何设置网页打开后5-10秒左右,只刷新一次就停止刷新。

setTimeout只会执行一次,所以,,,,

要想一直让他工作,要么用计时器

setInterval(function(){

????window.location.reload();?

},5000)

要么这样

function?refresh(){

????window.location.reload();

????setTimeout(refresh?,?5000);???

}

使用js写的刷新操作第一次运行可以,以后就不执行了,为什么?

太明显是缓存的问题了 ajax这个缓存问题解决起来也非常方便。

解决的办法就是你请求的URL地址的时候加个时间就好 ,浏览器的机制就是这样 。打个最简单的比方。你开第一网站 第一次可能是很慢的。当你开完了 在你没有清除缓存的时候你再开这个网站你就会快很多 因为这个网站的图片 css js文件这些已经缓存在你的机上了。你并没有去服务器重新接收 。

你ajax一个url请求也是同样的道理 你如果第一次请求的url是update_classify_change.jsp的话 那你下次就要加个时间 可以是

var oDate = new Date();

var getTime = oDate.getTime() ;

var url = "update_classify_change.jsp?time=" +getTime;

这样浏览器就不会缓存你的东西 因为他会认为你每次请求的东西都是不一样的。从而就不会给缓存。

我现在在某个页面插入了一段js代码,但是浏览器一刷新,这段代码就消失了。怎么让插入的js代码始终有

不过要注意几点:

1、这个代码是否可以执行,要看浏览器的安全设置,不是所有的JS都可以执行的

2、地址栏输入的长度限制,即URI的长度限制只能输入4096个字节,当然浏览器的地址栏可能会比这个更短

js第一次点击执行,刷新后就不执行了

引用jQuery的cookie库jquery.cookie.js

!--这里html的li要区分,这样便于添加完样式,刷新后再把样式还原,所以取了一个特别的值,也可以换成自己的--

!--如果是动态生成的更好,赋值动态的id--

ul?class="multiselect"

li?class="invsible?checkbox"?id="5W-30"a?title="5W-30"?href="/plus/list.php?tid=7jiyoubiaohao=5W-30"5W-30/a/li

li?class="invsible?checkbox"?id="10W-40"a?title="10W-40"?href="/plus/list.php?tid=7jiyoubiaohao=10W-40"10W-40/a/li

/ul

$(function(){

????$("li").click(function()?{

????//绑定点击事件,每次点击要把

????????$(this).addClass('act');?

????????var?id=$(this).attr('id');

????????//每次添加完样式要把添加的li的id记录到cookie

????????var?addedLI=$.cookie('addedLI');//获取已添加到cookie的值

????????if(addedLI==null||addedLI==""||addedLI==undefined){

????????????//首次点击li,只将当前li的id加入cookie

????????????$.cookie('addedLI',id);

????????}else{

????????????//已添加过id

????????????addedLI+=','+id;//将已加入的id和当前的id连接成字符串,逗号分隔

????????????//更新cookie

????????????$.cookie('addedLI',addedLI);

????????}

????});

????

????//页面加载完,获取存入cookie的id,分别给li加上class

????var?addedLI=$.cookie('addedLI');//获取已添加到cookie的值

????????if(addedLI!=null||addedLI!=""||addedLI!=undefined){

????????????//将加入的值以逗号分割成数据,然后循环遍历

????????????var?strArray=addedLI.split(',');

????????????for(var?i=0;istrArray.length;i++){

????????????????$("#"+strArray[i]).addClass('act');//给点击过的li添加上样式

????????????}

????????}

});

(责任编辑:IT教学网)

更多