问题描述
在我的aspx页面上,我有一个标签控件。
在每个标签中,我正在加载带有URL的Iframe。这个Iframe URL存储在db表中。
每个选项卡都有自己的Iframe。
选项卡是通过读取表中的数据动态生成的。
当焦点在iframe上并且用户按下后退按钮时,它会尝试在Iframe中加载前一个URL并给出404错误。
如何处理这个退格按钮的情况?
当用户点击浏览器后退按钮时会发生同样的事情。
有没有办法处理这两种情况?
任何帮助表示感谢。
我尝试过:
我尝试在javascript中捕获keydown事件上的KeyCode,并将window.location.href设置为同一页面。
这在父页面上运行良好。但是当关注选项卡内容时,我没有任何控制权。
同样对于我的父页面,我正在通过
protected void Page_Init(object Sender,EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();
}
Hi,
On my aspx page, I have a tab control.
In each tab I am loading an Iframe with URL. This Iframe URL is stored in a db table.
Each tab has its own Iframe.
Tabs are generated dynamically by reading a data in a table.
When focus is on Iframe and user presses back button, it tries to load previous url in Iframe and gives 404 error.
How can I handle this backspace button case?
Same thing happens when user click browser back button.
Is there any way to handle these two scenarios?
Any help appreciated.
What I have tried:
I tried capturing KeyCode on keydown event in javascript and set window.location.href to the same page.
This works well on parent page. But when focus is on tab content, I dont have any control over there.
Also for my parent page, I am disabling cache on Page Init event by
protected void Page_Init(object Sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();
}
推荐答案
document.onkeydown = function (e) {
try {
// IF backspace button is pressed, do not redirect the url.
// keycode for backspace - 8
if (e.keyCode === keyCode.backSpace) {
return false;
}
} catch (e) {
return true;
}
};
这篇关于如何禁用浏览器后退操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!