如何定位 iframe 中的 reCAPTCHA 元素以显示它,而不显示其他内容 (Gatsby/React)?

How do I target the reCAPTCHA element within an iframe to show it, and nothing else (Gatsby/React)?

LSS,我无法使用 jQuery 或额外的 CSS 文件。现在我正在从 shopify 加载一个 iframe 来处理联系表单提交。一切都很好,除了我将 iframe 设置为“显示:none”以便我可以添加我自己的样式联系表。唯一的问题是 iframe 包含 reCAPTCHA(“你不是机器人”的东西)我需要完成表单提交。

有没有一种简单的方法可以在 .js 文件中定位 reCAPTCHA,这样我就可以保留 reCAPTCHA,在调用它时将其放在我需要的位置,但隐藏 iframe 的所有其他部分?

现在 HTML 在我的 JSX 中看起来像这样。

  <iframe
    width='100%'
    height='100%'
    css={{ display: 'none' }}
    src='https://shop.examplestore.com/pages/contact-store'
  />

如果iframe是异源的,那么不行,你不能访问iframe的内容。

The same-origin policy is a critical security mechanism that restricts how a document or script loaded from one origin can interact with a resource from another origin. It helps isolate potentially malicious documents, reducing possible attack vectors.

Learn more about the same-origin policy here

如果文档是同一来源的一部分,您可以表面上操纵子 iframe 的 DOM 以隐藏验证码以外的任何内容,然后您也可以从中提交表单框架,使用 el.contentWindow(其中 el 是对 DOM 中相关 iframe 节点的引用)。