页面跳转刷新

不管在静态页面仍是动态输出页面中window.location.href都是不错的用了跳转的实现方案javascript

javascript中的location.href有不少种用法,主要以下。html

1 self.location.href="/url" 当前页面打开URL页面
2 location.href="/url" 当前页面打开URL页面
3 windows.location.href="/url" 当前页面打开URL页面,前面三个用法相同。
4 this.location.href="/url" 当前页面打开URL页面
5 parent.location.href="/url" 在父页面打开新页面
6 top.location.href="/url" 在顶层页面打开新页面

若是页面中自定义了frame,那么可将parent self top换为自定义frame的名称,效果是在frame窗口打开url地址java

此外,window.location.href=window.location.href;和window.location.Reload()和都是刷新当前页面。windows

区别在因而否有提交数据。当有提交数据时,window.location.Reload()会提示是否提交,window.location.href=window.location.href;则是向指定的url提交数据。服务器

window.location.href 语句能够实现一个框架的页面在执行服务器端代码后刷新另外一个框架的页面,框架

如:index.htm页面中有二个框架,分别为 frameLeft和frameRight,在frameRight页面中执行服务器端代码后刷新frameLeft中的页面。jsp

先前最多见的是注册以后,自动刷新登录框,让登录框换成已登录页面,只要在注册成功的代码以后加上一段,便可以实现刷新另个框架的页面。代码以下:this

1 < script language=javascript>alert('恭喜您,注册成功!')< /script>
2 < script language=javascript>window.parent.frameLeft.location.href='main.html'< /script>

"window.location.href"、"location.href"是本页面跳转
"parent.location.href"是上一层页面跳转
"top.location.href"是最外层的页面跳转url

举例说明:spa

若是A,B,C,D都是jsp,D是C的iframe,C是B的iframe,B是A的iframe,若是D中js这样写

"window.location.href"、"location.href":D页面跳转
"parent.location.href":C页面跳转
"top.location.href":A页面跳转

若是D页面中有form的话,

<form>: form提交后D页面跳转
<form target="_blank">: form提交后弹出新页面
<form target="_parent">: form提交后C页面跳转
<form target="_top"> : form提交后A页面跳转
 
关于页面刷新,D 页面中这样写:"parent.location.reload();": C页面刷新 (固然,也能够使用子窗口的 opener 对象来得到父窗口的对象:window.opener.document.location.reload(); )

"top.location.reload();": A页面刷新

相关文章
相关标签/搜索