如何在网络浏览器中禁用退格键
当我按 Backspace
时,Web-browser
将转到上一页。如何在不阻止清除文本功能的情况下禁用它?
When I press Backspace
, Web-browser
will go to previous page. How can I disable it without preventing the clearing text ability?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TWebBrowser似乎没有OnKeydown事件,而且它还有很多其他问题。我通常会忘记它并转到 TMembeddedWB (嵌入式 Web 浏览器组件包),它具有更好的功能。
我编写了一些代码来尝试检测我们是否处于编辑控件中,并且仅有条件地阻止退格键,因为正如 Paktas 所说,简单地阻止 OnKey 事件会中断编辑
网页表单,使用TMembeddedWB,代码如下:
TWebBrowser doesn't seem to have an OnKeydown event, and it also has many other problems. I usually forget it and go to TEmbeddedWB (embedded web browser component pack), and it has better features.
I wrote some code to try to detect if we are in an edit control, and only conditionally block backspace keys, since as Paktas says, simply blocking the OnKey event would break editing in
web page forms, using TEmbeddedWB, the code looks like this:
执行此操作的唯一方法是检查每次按键,如果检测到退格键,则忽略它。但是,您还需要监视您的任何输入是否具有焦点,以便用户仍然可以保留向后删除。
The only way for doing this is to check for each key press and if a backspace is detected ignore it. However you would also need to monitor whether any of your inputs are focused, so that users could stil preserve backwards deleting.