Javascript 通过网站中的按钮使用浏览器搜索 (Ctrl+F)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8080217/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 04:39:13  来源:igfitidea点击:

Use Browser Search (Ctrl+F) through a button in website?

javascriptasp.net

提问by Ashok Gupta

I have created a website and have added a button and lot of text. What I want is to use the browser search (Ctrl+F), when I press the button which I added in website.

我创建了一个网站并添加了一个按钮和大量文本。我想要的是使用浏览器搜索 ( Ctrl+ F),当我按下我在网站中添加的按钮时。

How can I achieve this?

我怎样才能做到这一点?

回答by Junaid

It kind of works for FF. See this page

它有点适用于 FF。看这个页面

 <a href="#" onclick="find();">Find in This Page...</a>

回答by Vignesh

update: from mark's comment:

更新:来自马克的评论:

From my testing window.find()is supported in Chrome 37, and FF31, but not IE11

window.find()Chrome 37 和 FF31 支持我的测试 ,但不支持 IE11

update:

更新:

for more information on this window.find go here

有关此窗口的更多信息。找到这里

回答by Piskvor left the building

No. In general, you cannot invoke browser controls from inside the webpage - security, sandboxing, and all that.

不可以。一般来说,您不能从网页内部调用浏览器控件 - 安全性、沙盒等等。

You need to make some sort of in-page search - if you're using a CMS, most of them have a simple search feature built-in.

您需要进行某种页面内搜索 - 如果您使用的是 CMS,它们中的大多数都内置了简单的搜索功能。

If you want to do this in JavaScript, there are various scripts that emulatethis in-page; randomly selected from my query "javascript find in page" is this one: http://www.seabreezecomputers.com/tips/find.htm

如果您想在 JavaScript 中执行此操作,可以使用各种脚本来模拟此页内内容;从我的查询“javascript find in page”中随机选择的是这个:http: //www.seabreezecomputers.com/tips/find.htm