简体   繁体   English

如何使用Javascript在Mozilla的页面开头设置搜索焦点?

[英]How can i set the search focus at the start of the page in Mozilla with Javascript?

I have some code that uses a native mozilla browser and it does a find on the text, however this works from wherever the user last clicked. 我有一些使用本机mozilla浏览器的代码,它可以在文本上进行查找,但是无论用户最后单击哪个位置,它都可以工作。 I need it to start from the top of the document but the API doesn't have any decent way of doing this so I was thinking it may be possible by executing javascript on the page. 我需要它从文档的顶部开始,但是API没有做到这一点的任何体面的方法,因此我认为可以通过执行页面上的javascript来实现。 Anyone know how to do this? 有人知道怎么做吗? Basically I want to set the caret position to 0. 基本上我想将插入符号的位置设置为0。

window.getSelection().selectAllChildren(document.body);
window.getSelection().collapseToStart();

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

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