简体   繁体   English

聆听浏览器Ctrl + F /查找布局修改

[英]Listening to browser Ctrl+F/find layout modifications

In the current minimal example ( http://jsfiddle.net/twPHW/ ) : 在当前的最小示例( http://jsfiddle.net/twPHW/ )中:

<div style="overflow: hidden; height: 24px;">

<table>
<thead>
<tr>
<td style="background-color: rgb(109,173,157);">foo</td>
</tr>
</thead>
<tbody>
<tr>
<td style="background-color: rgb(236,222,117);">bar</td>
</tr>
</tbody></table>

</div>

The "foo" cell is the only one visible. “ foo”单元格是唯一可见的单元格。 Then if I do Ctrl-F (find feature in browser), and start typing "bar", the table inside the div will goes up (like if its top changes) to show to the user the matched element. 然后,如果我执行Ctrl-F(在浏览器中查找功能)并开始键入“ bar”,则div内的表将上升(就像其顶部发生变化一样),以向用户显示匹配的元素。

I want to be able to look for "bar" through find feature, but I want to handle that layout modification through javascript. 我希望能够通过查找功能来查找“栏”,但是我想通过javascript处理该布局修改。

I know it is not possible to listen for browser "find" . 我知道不可能听浏览器“ find” I just would like to listen to this layout modification in order to prevent it or synchronize the rest of my view accordingly. 我只是想听听这个布局修改,以防止它或相应地同步其余视图。 I tried to listen to scroll events or to use Chrome Mutation Observer but it did not work. 我试图听滚动事件或使用Chrome Mutation Observer,但是它没有用。 Any idea ? 任何想法 ?

我尚未对此进行测试,但是一个选择是preventDefault() ctrl + f按键上的preventDefault() ,然后制作自己的查找功能版本。

I don't think it is possible to listen to those layout modifications. 我认为听这些布局修改是不可能的。

When the browser find an element, it is equivalent to call scrollIntoView for the matched element. 当浏览器找到一个元素时,它等效于为匹配的元素调用scrollIntoView Thus a scroll event will be fired only if the container div is scrollable. 因此,只有容器div可滚动时,才会触发滚动事件。

In the example, the parent style is overflow: hidden; 在该示例中,父样式为overflow: hidden; . Thus it does not trigger any scroll event. 因此,它不会触发任何滚动事件。

It becomes then impossible to listen to these layout change, because the only workaround that exist to listen to scroll event on overflow:hiden element, is to listen to mouse wheel event ... 这样就不可能监听这些布局更改,因为存在的唯一解决方法是监听overflow:hiden元素上的滚动事件,就是监听鼠标滚轮事件 ...

The bad story is that it is then impossible to prevent user from modifying layout through the browser find, because even if one can prevent Ctrl+F or F3 , we can't prevent user from using the Edit-> Find menu in Firefox or IE 糟糕的是,不可能阻止用户通过浏览器查找来修改布局,因为即使可以阻止Ctrl + F或F3 ,我们也不能阻止用户使用Firefox或IE中的“ Edit-> Find菜单

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM