当按下键盘中的空格按钮时,页面不应该转到另一页面 [英] page should not go another page when press back space button in keybord

查看:43
本文介绍了当按下键盘中的空格按钮时,页面不应该转到另一页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





i我正在使用.net 4.0,我创建了一个网站,但是当我们按下键盘中的后退空间按钮来编辑文本时,我丢失在我当前页面并转到任何其他页面或主页,我不明白我是如何解决这个问题,



i am using .net 4.0, and i create a web site but here when we press in back space button in keybord to edit a text, i loss in my current page and go to any other page or a home page, i am not understand how i resolve this problem,

推荐答案

我们也可以通过禁用来实现这一点代码中的浏览器缓存在Page_Init事件或Page_Load事件中编写以下代码行,并且不要忘记使用System.Web添加命名空间;因为与该命名空间相关的HttpCacheability





We can also achieve this by disabling browser caching in code behind write the following lines of code in Page_Init event or Page_Load event and don’t forgot to add namespace using System.Web; because HttpCacheability related to that namespace


protected void Page_Init(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();
}





我们需要将此代码放在我们需要禁用浏览器后退按钮的页面中。如果我们使用上面的缓存方法来禁用浏览器后退按钮,这将显示这样的网页过期消息



------------ - - - - - - - - - 要么 - - - - - - - - - - - - - - - - -----------------









< script type =text / javascript>



function preventBack(){window.history.forward( );}



setTimeout(preventBack(),0);



window.onunload = function(){null};



< / script>





我在以下浏览器中测试了脚本



1. Internet Explorer 5.55



2。 Internet Explorer 6



3. Internet Explorer 7



4. Mozilla Firefox 3



5.歌剧9



6. Safari 4



7.谷歌浏览器



We need to place this code in a page wherever we need to disable browser back button. If we use above caching method to disable browser back button that will display webpage expired message like this

------------------------------ OR ------------------------------------------------




<script type = "text/javascript" >

function preventBack(){window.history.forward();}

setTimeout("preventBack()", 0);

window.onunload=function(){null};

</script>


I have tested the script in the following browsers

1. Internet Explorer 5.55

2. Internet Explorer 6

3. Internet Explorer 7

4. Mozilla Firefox 3

5. Opera 9

6. Safari 4

7. Google Chrome


这篇关于当按下键盘中的空格按钮时,页面不应该转到另一页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆