js刷新页面方法大全文档格式.docx
- 文档编号:20300494
- 上传时间:2023-01-21
- 格式:DOCX
- 页数:8
- 大小:16.79KB
js刷新页面方法大全文档格式.docx
《js刷新页面方法大全文档格式.docx》由会员分享,可在线阅读,更多相关《js刷新页面方法大全文档格式.docx(8页珍藏版)》请在冰豆网上搜索。
的提示。
因为Session的安全保护机制。
当调用location.reload()方法时,aspx页面此时在服务端内存里已经存在,因此必定是IsPostback的。
如果有这种应用:
需要重新加载该页面,也就是说期望页面能够在服务端重新被创建,期望是NotIsPostback的。
这里,location.replace()就可以完成此任务。
被replace的页面每次都在服务端重新生成。
代码:
location.replace(location.href);
返回并刷新页面:
location.replace(document.referrer);
document.referrer//前一个页面的URL
不要用history.go(-1),或history.back();
来返回并刷新页面,这两种方法不会刷新页面。
附:
Javascript刷新页面的几种方法:
代码如下:
1,history.go(0)
2,location.reload()
3,location=location
4,location.assign(location)
5,document.execCommand('
Refresh'
6,window.navigate(location)
7,location.replace(location)
8,document.URL=location.href
自动刷新页面的方法:
1,页面自动刷新:
把如下代码加入&
lt;
head&
gt;
区域中
&
metahttp-equiv=&
refresh&
content=&
20&
其中20指每隔20秒刷新一次页面.
2,页面自动跳转:
20;
url=&
其中20指隔20秒后跳转到页面
3,页面自动刷新js版
scriptlanguage=&
JavaScript&
functionmyrefresh()
{
window.location.reload();
}
setTimeout('
myrefresh()'
1000);
//指定1秒刷新一次
/script&
4,JS刷新框架的脚本语句
//刷新包含该框架的页面用
scriptlanguage=JavaScript&
parent.location.reload();
//子窗口刷新父窗口
self.opener.location.reload();
( 或 &
ahref=&
javascript:
opener.location.reload()&
/a&
)
//刷新另一个框架的页面用
parent.另一FrameID.location.reload();
如果想关闭窗口时刷新或想开窗时刷新,在&
body&
中调用以下语句即可。
bodyonload=&
开窗时刷新
bodyonUnload=&
关闭时刷新
javascript&
window.opener.document.location.reload()
一、先来看一个简单的例子:
下面以三个页面分别命名为frame.html、top.html、bottom.html为例来具体说明如何做。
frame.html由上(top.html)下(bottom.html)两个页面组成,代码如下:
!
DOCTYPEHTMLPUBLIC&
-//W3C//DTDHTML4.0Transitional//EN&
HTML&
HEAD&
TITLE&
frame&
/TITLE&
/HEAD&
framesetrows=&
50%,50%&
framename=topsrc=&
top.html&
framename=bottomsrc=&
bottom.html&
/frameset&
/HTML&
现在假设top.html(即上面的页面)有七个button来实现对bottom.html(即下面的页面)的刷新,可以用以下七种语句,哪个好用自己看着办了。
top.html页面的代码如下:
top.html&
BODY&
inputtype=buttonvalue=&
刷新1&
onclick=&
window.parent.frames[1].location.reload()&
br&
刷新2&
window.parent.frames.bottom.location.reload()&
刷新3&
window.parent.frames['
bottom'
].location.reload()&
刷新4&
window.parent.frames.item
(1).location.reload()&
刷新5&
window.parent.frames.item('
).location.reload()&
刷新6&
window.parent.bottom.location.reload()&
刷新7&
window.parent['
/BODY&
下面是bottom.html页面源代码,为了证明下方页面的确被刷新了,在装载完页面弹出一个对话框。
bottom.html&
BODYonload=&
alert('
我被加载了!
'
)&
h1&
Thisisthecontentinbottom.html.&
/h1&
解释一下:
1.window指代的是当前页面,例如对于此例它指的是top.html页面。
2.parent指的是当前页面的父页面,也就是包含它的框架页面。
例如对于此例它指的是framedemo.html。
3.frames是window对象,是一个数组。
代表着该框架内所有子页面。
4.item是方法。
返回数组里面的元素。
5.如果子页面也是个框架页面,里面还是其它的子页面,那么上面的有些方法可能不行。
1history.go(0)
2location.reload()
3location=location
4location.assign(location)
5document.execCommand('
6window.navigate(location)
7location.replace(location)
8document.URL=location.href
二、自动刷新页面
1.页面自动刷新:
2.页面自动跳转:
3.页面自动刷新js版
[Ctrl+A全选注:
如需引入外部Js需刷新才能执行]
三、java在写Servler,Action等程序时,要操作返回页面的话(如谈出了窗口,操作完成以后,关闭当前页面,刷新父页面)
1PrintWriterout=response.getWriter();
2out.write(&
scripttype=\&
text/javascript\&
);
3////子窗口刷新父窗口
4out.write(&
self.opener.location.reload();
5//关闭窗口
6out.write(&
window.opener=null;
7out.write(&
window.close();
8out.write(&
四、JS刷新框架的脚本语句
1.如何刷新包含该框架的页面用
parent.location.reload();
2.子窗口刷新父窗口
3.如何刷新另一个框架的页面用(上面的实例以说明了)
语句1.window.parent.frames[1].location.reload();
语句2.window.parent.frames.bottom.location.reload();
语句3.window.parent.frames[&
bottom&
].location.reload();
语句4.window.parent.frames.item
(1).location.reload();
语句5.window.parent.frames.item('
).location.reload();
语句6.window.parent.bottom.location.reload();
语句7.window.parent['
4.如果想关闭窗口时刷新或者想开窗时刷新的话,在&
开窗时刷新
关闭时刷新
您可能感兴趣的文章:
∙刷新页面的几种方法小结(JS,ASP.NET)
∙JSP刷新页面表单重复提交问题解决办法分享
∙js局部刷新页面时间具体实现
∙JS定时刷新页面及跳转页面的方法
∙js刷新页面的代码小结推荐
∙刷新页面实现方式总结(HTML,ASP,JS)
∙js离开或刷新页面检测(且兼容FF,IE,Chrome)
查看文档来源:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- js 刷新 页面 方法 大全
![提示](https://static.bdocx.com/images/bang_tan.gif)