zoukankan      html  css  js  c++  java
  • javascript.history.go();

    转自:http://www.mikebai.com/Article/2009-11/757.html
    
    <input type=button value=刷新 onclick="window.location.reload()">
    <input type=button value=前进 onclick="window.history.go(1)">
    <input type=button value=后退 onclick="window.history.go(-1)">
    <input type=button value=前进 onclick="window.history.forward()">
    <input type=button value=后退 onclick="window.history.back()"> 后退+刷新<input type=button value=后退 onclick="window.history.go(-1);window.location.reload()">在C# Web程序中,如为页面按钮写返回上一页代码
    
    this.RegisterClientScriptBlock("E", "<script language=javascript>history.go(-2);</script>");
    
    其中,history.go(-2),要写为-2,因在按钮事件触发前,已刷新一次页面,所以应是-2。
    
    Response.Write("<script language=javascript>history.go(-2);</script>");
    
    此处也要写为“-2”。跟直接写脚本的有所不同。history.back()是会上一页
    i=1
    history.go(i)去指定的某页
    如果是history.go(0)那就是刷新这两个属于JS代码,相当于IE的前进、后退功能。
    具体的用处就要看什么时候需要这个就用上。比如用户注册时的验证是后台验证,不符合要求的时候就可以用这个,可以最大限度保证用户少重复输入数据。
    例如:载入页面:
       function onLoadPage(){
         if(event.srcElement.tagName=="SPAN"){
             oFrame=top.window.middle.frames[2];
             oTxt=event.srcElement.innerText;
             switch(oTxt){
                 case "前 进":
                     oFrame.history.go(1);
                 case "后 退":
                     oFrame.history.back();
                 case "刷 新":
                     oFrame.location.reload();
             }
         }
    }
    
    
    打开一个jsp页面,肯定是用客户端脚本进行刷新了。
    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
    
    作者:于为源 出处: http://www.cnblogs.com/yuanyuan/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    

      

     
  • 相关阅读:
    SP3946 MKTHNUM
    P1948 [USACO08JAN]电话线Telephone Lines(二分答案+最短路)
    CF375D Tree and Queries(dsu on tree)
    P2051 [AHOI2009]中国象棋(动态规划)
    P3810 【模板】三维偏序(陌上花开)(cdq分治)
    P4390 [BOI2007]Mokia 摩基亚(cdq分治)
    P2163 [SHOI2007]园丁的烦恼(cdq分治)
    UVA11270 Tiling Dominoes(轮廓线动态规划)
    P2475 [SCOI2008]斜堆(递归模拟)
    P2617 Dynamic Rankings(带修主席树)
  • 原文地址:https://www.cnblogs.com/Kqingniao/p/6703892.html
Copyright © 2011-2022 走看看