我如何以编程方式触发我的浏览器搜索? [英] How can I programmatically trigger the search of my browser?
问题描述
我喜欢做的是以编程方式从JavaScript触发浏览器的页面内搜索功能。
I。当一个页面被加载并且用户按下 Ctrl + F 时,搜索栏打开并且用户可以输入搜索词。这通常会导致,根据使用的浏览器,在所有突出显示的事件中。
我想在我的页面上执行相同的操作:
- 调用浏览器的某个JavaScript API来触发搜索字段。
- 调用浏览器的JavaScript API以在搜索中输入值
- 实际执行搜索。
- Call some JavaScript API of the browser to trigger the search field.
- Call some JavaScript API of the browser to enter values into the search field.
- Actually execute the search.
尽管我认为这是不可能的,对于可能的安全隐患,我仍然想确定。
b是否有可能以编程方式触发Web浏览器的页面内搜索功能?
(如果没有通用API,可能是浏览器特定的如何做到这一点)
非标准 window#find
,目前支持chrome和f F。然而,支持并不能保证:
setTimeout(function(){find( 'text');},1000);
< p>我是文字< / p>
What I like to do is to programmatically trigger the on-page search functionality of my browser from JavaScript.
I.e. when a page is loaded and the the user presses Ctrl+F, a search field is opened and the user can enter a search term. This usually results, depending on the used browser, in all occurances being highlighted.
I want to do the same on my page:
While I think it is not possible, due to possible security-risks, I still want to be sure.
Therefore my question:
Is it possible to programmatically trigger the on-page search function of a web browser?
(If there is no general API, maybe there are browser-specific ways of doing it)
There is the non standard window#find
, currently supported by chrome and ff. However, support is not guaranteed:
setTimeout(function() {
find('text');
}, 1000);
<p>I'm the text</p>
这篇关于我如何以编程方式触发我的浏览器搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!