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

javascript中的location.href有很多种用法,主要如下。

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

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

此外,window.location.href=window.location.href;和
window.location.Reload()和都是刷新当前页面。区别在于是否有提交数据。当有提交数据
时,window.location.Reload()会提示是否提
交,window.location.href=window.location.href;则是向指定的url提交数据

在写ASP.Net程序的时候,我们经常遇到跳转页面的问题,我们经常使用Response.Redirect 做ASP.NET框架页跳转,如果客户要在跳转的时候使用提示,这个就不灵光了,如:

复制代码 代码如下:
Response.Write("< script>alert('恭喜您,注册成功!');< /script>"); 
Response.Redirect("main.html");  

这时候我们的提示内容没有出来就跳转了,和Response.Redirect("main.html");没有任何区别。

这时我们采用下面代码试验一下:

ASP.NET框架页跳转的另一实现

复制代码 代码如下:
Response.Write("< script language=javascript>alert('恭喜您,注册成功!')< /script>"); 
Response.Write("< script language=javascript>window.location.href='main.html'< /script>");

这个即实现了我们的要求,在提示后,跳转页面。

最重要的是window.location.href 语句可以实现一个框架的页面在执行服务器端代码后刷新另一个框架的页面(Response.Redirect无法达到,至少我没有发现):

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

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

复制代码 代码如下:
Response.Write("< script language=javascript>alert('恭喜您,注册成功!')< /script>"); 
Response.Write("< script language=javascript>window.parent.frameLeft.location.href='main.html'< /script>");  

这样就搞定了ASP.NET框架页跳转中断的问题。其实asp、php中一般都使用这种方式。

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

举例说明:

如果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页面刷新

[转载]window.location.href的用法(动态输出跳转)的更多相关文章

  1. window.location.href的用法

    在写ASP.Net程序的时候,我们经常遇到跳转页面的问题,我们经常使用Response.Redirect 做ASP.NET框架页跳转,如果客户要在跳转的时候使用提示,这个就不灵光了,如: Respon ...

  2. 关于js中window.location.href,location.href,parent.location.href,top.location.href的用法

    "window.location.href"."location.href"是本页面跳转 "parent.location.href"是上一 ...

  3. window.open和window.location.href的几种用法

    windows.open("URL","窗口名称","窗口外观设定"); <A href="javascript:windo ...

  4. 关于js中"window.location.href"、"location.href"、"parent.location.href"、"top.location.href"的用法

    location.href 和 window.location.href 区别: 1.location.href 可以直接跳转其他地址(不属于本项目) 也可以跳转本项目中的 2.window.loca ...

  5. 关于js中window.location.href,location.href,parent.location.href,top.location.href的用法与区别(跳出iframe方法)

    "window.location.href"."location.href"是本页面跳转 "parent.location.href"是上一 ...

  6. 关于js中window.location.href,location.href,parent.location.href,top.location.href用法

    "window.location.href"."location.href"是本页面跳转 "parent.location.href"是上一 ...

  7. window.location.href用法与a标签的比较

    1.在使用这两种方法进行页面的跳转时,这两种方法都能够有效的实现该功能 但是其原理不尽相同 第一:window.location.href()方法必须书写在js中 <html> <h ...

  8. js中location.href的用法

    Javascript中的location.href有很多种用法,主要如下: self.location.href="/url" 当前页面打开URL页面 ocation.href=& ...

  9. window.location.href和window.open的几种用法和区别

    使用js的同学一定知道js的location.href的作用是什么,但是在js中关于location.href的用法究竟有哪几种,究竟有哪些区别,估计很多人都不知道了. 一.location.href ...

随机推荐

  1. UNDERSTANDING ITWEEN CALLBACKS

    One of the most frequent problems I see people have with iTween is with callbacks that don't fire. A ...

  2. adb移动端测试

    1. Android介绍 Android 是google公司主导的一个开放的手机操作系统,不过目前已经超过了手机的局限,而定位于移动设备的操作系统. Android一词的本义指“机器人”,取名原因很简 ...

  3. CA证书和TLS介绍

    数字签名 用自己的私钥给数据加密就叫数字签名 公钥传输威胁 在A和B的通信中,C可以把自己的公钥发给A,让A把C的公钥当成B的公钥,这样的话.B拿到加密数据反而无法解密,而C却可以解密出数据.从而实现 ...

  4. C++ 常用算法

    http://blog.csdn.net/jgzquanquan/article/details/77185711

  5. Redis入门到高可用(四)—— Redis的五种数据结构的内部编码

    Redis的五种数据结构的内部编码

  6. PHP自动加载SPL的四种处理方式

    libs目录下有3个类文件: Test.class.php <?php class Test { public function __construct() { echo "Loadi ...

  7. Java知识点-判断null、空字符串和空格

    Java知识点-判断null.空字符串和空格 // 判断headerKey是否为null,空字符串或者空格 if (headerKey != null && headerKey.len ...

  8. js中实现IE的打印预览

    HTML中添加:<object id="WebBrowser" classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 widt ...

  9. NgDL:第四周深层神经网络

    4.3核对矩阵维数 根据前向的矩阵,可以计算出右上的规律,对于第L层的w来说,其维数为(n[L],n[L-1]),n[L]表示第L层的单元数. 4.4为什么深层神经网络会好用? 如果要做一个人脸识别的 ...

  10. 【Java】-NO.16.EBook.4.Java.1.006-【疯狂Java讲义第3版 李刚】- 垃圾回收

    1.0.0 Summary Tittle:[Java]-NO.16.EBook.4.Java.1.006-[疯狂Java讲义第3版 李刚]- 垃圾回收 Style:EBook Series:Java ...