我如何以编程方式触发我的浏览器搜索? [英] How can I programmatically trigger the search of my browser?

查看:145
本文介绍了我如何以编程方式触发我的浏览器搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢做的是以编程方式从JavaScript触发浏览器的页面内搜索功能。



I。当一个页面被加载并且用户按下 Ctrl + F 时,搜索栏打开并且用户可以输入搜索词。这通常会导致,根据使用的浏览器,在所有突出显示的事件中。



我想在我的页面上执行相同的操作:


  1. 调用浏览器的某个JavaScript API来触发搜索字段。

  2. 调用浏览器的JavaScript API以在搜索中输入值

  3. 实际执行搜索。


  4. 尽管我认为这是不可能的,对于可能的安全隐患,我仍然想确定。

    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:

    1. Call some JavaScript API of the browser to trigger the search field.
    2. Call some JavaScript API of the browser to enter values into the search field.
    3. Actually execute the search.

    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屋!

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