如何在iframe中使用JavaScript突出显示IFRAME中的文本

发布于 2025-02-08 02:47:29 字数 591 浏览 2 评论 0原文

PDF文档将显示在iFrame标签中。当页面加载将发送一个文本时。如果在PDF中找到文本,则应在PDF中突出显示在iFrame中。 我可以在iframe中显示PDF文档。但是我找不到如何突出文本。您能使用JavaScript提供此问题吗?

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
  <script type="text/javascript">
   
  </script>

<iframe id="myIFrame"  width="100%" height="500px"src = "http://www.africau.edu/images/default/sample.pdf#page=1"; ></iframe>
  </body>
</html>

The pdf document will display in the iframe tag. When the page loads will send one text. In case text is found in the pdf then it should be highlighted in the pdf into the iframe.
I am able to show the PDF document in the iframe. But I am not able to find how to highlight the text. Could you please help with this issue using javascript?

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
  <script type="text/javascript">
   
  </script>

<iframe id="myIFrame"  width="100%" height="500px"src = "http://www.africau.edu/images/default/sample.pdf#page=1"; ></iframe>
  </body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

祁梦 2025-02-15 02:47:29

当您提供PDF时,它不再是您的编辑,现在它属于客户端的所有权,他们可以将其编辑为自己的应用程序/PDF方式。因此,您不能在其设备中运行JavaScript,它将违反其所有权。但是,Acrobat或其他商业方法可能使您可以通过搜索等片段进行交互。

铬变体

Safari变体

在Acrobat浏览器插件中,您可以指定#search = Word,但是除非您是Intranet服务器,否则您不能坚持您的用户只使用Acrobat或任何其他付费用于解决方案。但是,可以在Firefox(使用PDF.JS,因此并非所有Mozilla浏览器)中使用相同的功能。因此,在Firefox中触发突出显示简单将您的代码更改为: -

<iframe id="myIFrame"  width="100%" height="500px" src="http://www.africau.edu/images/default/sample.pdf#search=Simple"; ></iframe>

“在此处输入映像说明”

,但是它似乎对更安全的Chromium/Edge/opera等似乎不起作用。
并非所有Firefox变体都可能显示出PDF,因此Cyber​​fox设置为保护。

When you serve a PDF it is no longer yours to edit, it is now in the ownership of the client, and they can edit it their own application/pdf way. Therefore you cannot run JavaScript inside their device it would breach their ownership rights. However Acrobat or other commercial methods may allow you to offer to interact via a fragment such as search.

Chromium variant
enter image description here

Safari variant
enter image description here

In Acrobat browser Plug-in you can specify #search=word but unless you are an intranet server you can not insist your users are only using Acrobat, or any other paid for solution. But the same function can be used in FireFox (with PDF.js, so not all Mozilla browsers). Thus to trigger highlighting Simple in Firefox change your code to:-

<iframe id="myIFrame"  width="100%" height="500px" src="http://www.africau.edu/images/default/sample.pdf#search=Simple"; ></iframe>

enter image description here

However it does NOT appear to work for more secure Chromium/Edge/Opera etc.
and not all FireFox variants may show a PDF, here CyberFox is set to secured.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文