首页 > 技术文章 > JS实现页面跳转

zhabayi 2017-02-22 11:06 原文

js实现页面的跳转具体有几种方法:

location.href :表示当前页面链接地址

例子:最外层页面为(main.html主页面)分上(top.html)页面,左(left.html)页面,右(right.html页)面3个<frame>子页面,

http://localhost:8080/Spring_shizhan4ban_Chapter05/resources/js/main.html

http://localhost:8080/Spring_shizhan4ban_Chapter05/resources/js/top.html

http://localhost:8080/Spring_shizhan4ban_Chapter05/resources/js/right.html

http://localhost:8080/Spring_shizhan4ban_Chapter05/resources/js/left.html

main.html代码如下:

<div id="frameset">
    <frameset rows="11%,*" >        
        <frame src=top.html name="top" frameborder=0 noresize >
        <frameset cols="20%,*" name="buttom">
         <frame src=left.html name="left"  id="left" >
         <frame src=right.html name="right" id="right" >
        </frameset>
    </frameset> 
</div>

主界面窗口如下图:

 点击生成密码在右子窗口进行表单提交:

在点击确认修改按钮后的几种跳转:

1.在检查提交时后台表单项检查不通过,刷新或者是重新加载右页面重新输入:window.location.reload(true);

2.在检查表单通过时跳转到登录界面重新登录,那么这个时候需要将主界面(main.html)置为登录的主界面:top.location="../../home";

 

其他相关页面标示符的含义:

1.top
该变更永远指分割窗口最高层次的浏览器窗口。如果计划从分割窗口的最高层次开始执行命令,就可以用top变量。 
2.opener
opener用于在window.open的页面引用执行该window.open方法的的页面的对象。例如:A页面通过window.open()方
法弹出了B页面,在B页面中就可以通过opener来引用A页面,这样就可以通过这个对象来对A页面进行操作。 
3.parent
parent用于在iframe,frame中生成的子页面中访问父页面的对象。例如:A页面中有一个iframe或frame,那么iframe
或frame中的页面就可以通过parent对象来引用A页面中的对象。这样就可以获取或返回值到A页面中。
4.另外self 指的是当前窗口

parent与opener的区别:

parent指父窗口,在FRAMESET中,FRAME的PARENT就是FRAMESET窗口。 
opener指用WINDOW.OPEN等方式创建的新窗口对应的原窗口。 
parent是相对于框架来说父窗口对象 
opener是针对于用window.open打开的窗口来说的父窗口,前提是window.open打开的才有

document.parentWindow.menthod()調用父頁面的方法

附:Window对象、Parent对象、Frame对象、Document对象和Form对象的阶层关系 
Window对象→Parent对象→Frame对象→Document对象→Form对象,
如下: parent.frame1.document.forms[0].elements[0].value;

推荐阅读