zoukankan      html  css  js  c++  java
  • JS页面跳转和js对iframe进行页面跳转、刷新

    一、js方式的页面跳转
    1.window.location.href方式

    <script language="JavaScript" type="text/javascript">
          window.location.href="http://www.dayanmei.com/";
    </script>

    2.window.navigate方式跳转 Firefox不支持

     <script language="javascript">
        window.navigate("top.jsp");
      </script> 

    如果:top.jsp中有Iframe则,top.jsp在iframe中打开。(IE6测试过);
    3.window.loction.replace方式实现页面跳转,注意跟第一种方式的区别

    <script language="javascript">
        window.location.replace("http://www.dayanmei.com");
    </script>

    有3个jsp页面(a.jsp, b.jsp, c.jsp),进系统默认的是a.jsp ,当我进入b.jsp的时候, b.jsp里面用window.location.replace("c.jsp");与用window.location.href ="c.jsp";从用户界面来看是没有什么区别的,但是当c.jsp页面有一个"返回"按钮,调用window.history.Go(-1); wondow.history.back();方法的时候,一点这个返回按钮就要返回b.jsp页面的话,区别就出来了,当用 window.location.replace("c.jsp");连到c.jsp页面的话,c.jsp页面中的调用 window.history.go(-1);wondow.history.back();方法是不好用的,会返回到a.jsp 。
    4.self.location方式实现页面跳转,和下面的top.location有小小区别

    <script language="JavaScript">
        self.location='top.htm';
    </script>

    5.top.location

    <script language="javascript">
         top.location='xx.jsp';
    </script>

    6.不推荐这种方式跳转

     <script language="javascript">
        window.history.back(-1);
     </script>

    7.页面自动刷新:把如下代码加入<head>区域中 <meta http-equiv="refresh" content="20"> 其中20指每隔20秒刷新一次页面.

    8.<a href="javascript:history.go(-1)">返回上一步</a>

    9.<a href="<%=Request.ServerVariables("HTTP_REFERER")%>">返回上一步</a>

    10.<a href="javascript:" onClick="window.open('http://hi.baidu.com/630270730','','height=500,width=611,scrollbars=yes,status=yes')">打开新窗口</a>

    11.window.history.forward()返回下一页

    12. window.history.go(返回第几页,也可以使用访问过的URL)

    二、iframe中页面跳转

    1.iframe页面跳转:
    
    "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页面跳转 
    
    2.iframe中的target
    
    如果D页面中有form的话,  form提交后D页面跳转
    
    <form target="_blank">:  form提交后弹出新页面
    
    <form target="_parent">:  form提交后C页面跳转
    
    <form target="_top"> :  form提交后A页面跳转

    三.iframe页面刷新

    D 页面中这样写:"parent.location.reload();": C页面刷新  
    
    (当然,也可以使用子窗口的 opener 对象来获得父窗口的对象:window.opener.document.location.reload(); )
    
    "top.location.reload();": A页面刷新
    window.location.href = window.location.href 
    也可以实现页面刷新,它与reload的区别是:如果在reload之前想服务器提交过数据,那么执行reload会重新执行这个提交操作。
    而window.location.href = window.location.href 则不会,因为它是重新进入页面。 //子窗口刷新父窗口
    <script language=JavaScript> self.opener.location.reload(); </script> (或<a href="javascript:opener.location.reload()">刷新</a> ) //如何刷新另一个框架的页面用 <script language=JavaScript> parent.另一FrameID.location.reload(); </script>
  • 相关阅读:
    RE
    【LeetCode】198. House Robber
    【LeetCode】053. Maximum Subarray
    【LeetCode】152. Maximum Product Subarray
    【LeetCode】238.Product of Array Except Self
    【LeetCode】042 Trapping Rain Water
    【LeetCode】011 Container With Most Water
    【LeetCode】004. Median of Two Sorted Arrays
    【LeetCode】454 4Sum II
    【LeetCode】259 3Sum Smaller
  • 原文地址:https://www.cnblogs.com/yu-shang/p/12392473.html
Copyright © 2011-2022 走看看