杀死在Firefox / IE的默认CTRL-F搜索栏 [英] Kill default CTRL-F search bar in Firefox/Internet Explorer

查看:172
本文介绍了杀死在Firefox / IE的默认CTRL-F搜索栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在设计一个网页,提供个性化的搜索功能。因为这可能与浏览器上提供的默认搜索栏干扰<大骨节病> CTRL - <大骨节病>˚F,我们禁用事件,这样的默认搜索栏不会弹出,我们的显示来代替。

I am currently designing a web page which provides customized search functionality. Since that might interfere with the default search bar provided by browsers on CTRL-F, we are disabling the event so that the default search bar does not pop up, ours show up instead.

问题是,在Firefox和Internet Explorer,不像Chrome或Safari或Opera,搜索栏是所有选项卡之间共享。所以,如果我在其他一些选项卡,做了<大骨节病> CTRL - <大骨节病>˚F弹出默认的搜索栏,现在跳转到该页面,搜索栏仍然存在,这完全违背了我们的目的。

Problem is that, in Firefox and Internet Explorer, unlike Chrome or Safari or Opera, the search bar is sharable among all tabs. So if I am in some other tab, do a CTRL-F to pop up the default search bar, and now jump to this page, the search bar is still there, which defeats our purpose entirely.

我知道这听起​​来不可能的,不过,有没有什么办法杀默认的搜索栏,也就是隐藏它完全通过JavaScript?然后,当我们发现用户在Tab键切换到我们的页面,我们可以做到这一点。

I know it sounds impossible, but still, is there any way to kill the default search bar, that is, hide it completely through JavaScript? Then we might do it when we detect the user is tabbing into our page.

如果这是不可能的,那么有没有什么办法可以禁用特定元素的默认搜索,说 DIV CONTENTEDITABLE ?因此,虽然<大骨节病> CTRL - <大骨节病>˚F遍历这个词的页面,突出与<大骨节病> ENTER 每个preSS每个实例,所有该元素的话被完全忽略?

And if it is not possible, then is there any way I can disable the default search for a particular element, say a contenteditable div? So that, while the CTRL-F iterates over the page for the word, highlighting every instance with each press of ENTER, all words in that element are completely ignored?

推荐答案

看起来你已经听了<大骨节病>控制 + <大骨节病>˚F键presses和SUP pressing的默认行为。这是至于你可以走了。

It looks like you're already listening for Ctrl+F keypresses and suppressing the default behavior. This is as far as you can go.

在换句话说,回答你的问题是很简单的

In other words, the answer to your question is quite simply NO.

这一发现,在网页搜索栏是chrome浏览器的一部分;你不必通过DOM或以其他方式访问它的任何方式。浏览器不提供任何形式的API,允许网页控制以任何方式查找,在页面的功能。你不能关闭查找栏已经打开。你不能导致其被打开。您无法读取或控制的是在搜索输入框。

The find-in-page search bar is part of the browser chrome; you do not have any way of accessing it through the DOM or otherwise. Browsers do not provide any kind of API that allows a page to control the find-in-page functionality in any way. You cannot close a find bar that is already open. You cannot cause it to be opened. You cannot read or control what is in the search input box.

您可能能够编写控制以某种方式查找,在网页功能的扩展,但很明显,你必须说服用户安装它,你需要一个您指定的每个浏览器。

You may be able to write an extension that controls the find-in-page functionality in some way, but obviously you'd have to convince users to install it and you'd need one for each browser you're targeting.

坦率地说,任何时候我看到有人要求禁用或默认的浏览器行为的干涉,它通常是一个误导,坏主意。你可能会认为你的搜索功能是超级真棒(毕竟,你写的),但你可能会限制你的用户在一些意想不到的方式。 (我不能肯定地说没有看到您的具体使用情况,但这是一个很好的一般规则。)

Quite frankly, any time I see someone asking to disable or interfere with default browser behavior, it is usually a misguided, bad idea. You might think your search functionality is super awesome (after all, you wrote it), but you might be limiting your users in some unexpected way. (I can't say for sure without seeing your exact use case, but this is a good general rule.)

如果你想击败标准的浏览器功能,你可能的做错了

If you're trying to defeat standard browser functionality, you're probably doing it wrong.

这篇关于杀死在Firefox / IE的默认CTRL-F搜索栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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