`
xiangqian0505
  • 浏览: 317089 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

javascript:history.go()和History.back()的区别

阅读更多

<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

分享到:
评论

相关推荐

    javascript-history.go()和History.back()的区分_.docx

    javascript-history.go()和History.back()的区分_.docx

    js实现上一页下一页的效果【附代码】

    1. history.go(-1), 返回两个页面: history.go(-2); 2. history.back(). 3. window.history.forward()返回下一页 4. window.history.go(返回第几页,也可以使用访问过的URL) 例: 复制代码 代码如下: 向上一页 ...

    JavaScript常用的返回,自动跳转,刷新,关闭语句汇总

    1. Javascript 返回上一页: 代码如下:history.go(-1)返回两个页面: 代码如下:history.go(-2)    2. 后退: 代码如下:history.back() 3. 返回下一页: 代码如下:window.history.forward() 4. 返回第几页,也可以...

    107个常用javascript语句

    90.window.history.back()返回上一页,window.history.forward()返回下一页,window.history.go(返回第几页,也可以使用访问过的URL) 91.document.write()不换行的输出,document.writeln()换行输出 92.document.body....

    [removed]history.go()和History.back()的区别及应用

    input type=button value=前进 onclick=”window.history.go(1)”&gt; &lt;input type=button value=后退 onclick=”window.history.go(-1)”&gt; &lt;input type=button value=前进 onclick=”window.history....

    JavaScript Window History

    JavaScript Window History window.history 对象包含浏览器的历史。 Window History window.history对象在编写时可不使用 window 这个前缀。 为了保护用户隐私,对 JavaScript 访问该对象的方法做出了限制。 一些...

    javascript-study-notes:前端学习笔记和练习,包含JavaScript,Node.js Vue.js React等!

    重要的方法: history.go()/history.back()/history.forward() history.pushState(state, title, url); history.replaceState(state, title, url); onpopstate 会监听 go()/back()/forward()操作 [removed] = ...

    javascript常用对象梳理

    JS中的常用对象[转载]web 技术 2010-06-05 15:00:30 阅读3 评论0 字号:大中小 订阅 [removed] Window For JavaScript 熟练window对象的open、close、... window对象的子对象history是javascript的核心对象之一,该...

    javascript函数的解释

    90.window.history.back()返回上一页,window.history.forward()返回下一页,window.history.go(返回第几页,也可以使用访问过的URL) 91.document.write()不换行的输出,document.writeln()换行输出 92.document.body....

    js 刷新页面的代码小结 推荐

    1. Javascript 返回上一页 history.go(-1), 返回两个页面: history.go(-2); 2. history.back(). 3. window.history.forward()返回下一页 4. window.history.go(返回第几页,也可以使用访问过的URL) 例: 向上一页&lt;/a&gt; ...

    js 返回上一页和刷新 的代码

    1. Javascript 返回上一页history.go(-1), 返回两个页面: history.go(-2);2. history.back().3. window.history.forward()返回下一页4. window.history.go(返回第几页,也可以使用访问过的URL) 例:向上一页&lt;/a&gt;...

    【JavaScript源代码】今天分享几个少见却很有用的 JS 技巧.docx

     &lt;button onclick="history.back()"&gt; 返回 &lt;/button&gt; 2. 数字分隔符 为了提高数字的可读性,您可以使用下划线作为分隔符: const largeNumber = 1_000_000_000; console.log(largeNumber); // 1000000000 3....

    73种网页常用Javascript代码

    1、后退 前进 后退" onClick="history.go(-1)"&gt; 前进" onClick="history.go( 1 );return true;"&gt; 2、返回 &lt;form&gt;&lt;input type="button" value="返回上一步" onClick="history.back(-1)"&gt;&lt;/form&gt; 3、查看源码 查看源码...

    详解HTML5之pushstate、popstate操作history,无刷新改变当前url

    window.history表示window对象的历史记录,是由用户主动产生,并且接受javascript脚本控制的全局对象。window对象通过history对象提供对览器历史记录的访问能力。它暴露了一些非常有用的方法和属性,让你在历史记录...

    javascript history对象(历史记录)使用方法(实现浏览器前进后退)

    window.history对象在编写时可不使用 window 这个前缀。...button name=”back” value=”后退” onclick=”goBack()”&gt;后退&lt;/button&gt;&lt;button name=”forward” value=”前进” onclick=”

    js中document.referrer实现移动端返回上一页

    返回上一页,在PC端我们可以使用:history.go(-1)或者history.back(),可以正常返回第一层。这样,我们不需要上一页的 url 具体是什么,只要使用 history 一般都没啥问题。 但是在移动端,如果想要返回上一页。比如...

    JavaScript返回上一页的三种方法及区别介绍

    JavaScript返回上一页代码区别: window.history.go(-1); //返回上一页 window.history.back(); //返回上一页 //如果要强行刷新的话就是:window.history.back();location.reload(); [removed].go(-1); //刷新上一...

    javascript学习笔记.docx

    支持三种方法back()、forword()、go()。 13) 一个窗口中的任何框架都可以使用属性frames、parent和top引用窗口中的其它框架。 14) 若框架指定了名字,引用就会被存储到它的父Window对象的一个同名新属性中。 15) ...

    【JavaScript源代码】vue浏览器返回监听的具体步骤.docx

    vue浏览器返回监听的具体步骤 ... 需要监听浏览器的回退按钮,并阻止其默认事件。 具体步骤如下: 1、挂载完成后,判断浏览器... window.addEventListener('popstate', this.goBack, false); } }, 2、页面销毁时

    JavaScript入门教程(7) History历史对象

    鉴于安全性的需要,该对象收到很多限制,现在只剩下下列属性和方法。... go() 用法:history.go(x);在历史的范围内去到指定的一个地址。如果 x &lt; 0&gt; 0,则前进 x 个地址,如果 x == 0,则刷新现在

Global site tag (gtag.js) - Google Analytics