【问题标题】:How to set focus on an iframe that is cross-domain如何将焦点设置在跨域的 iframe 上
【发布时间】:2020-05-17 12:32:33
【问题描述】:

类似于下面的帖子:

  1. Set focus on iframe in Chrome

  2. Setting focus to iframe contents

我希望能够从根/父级将焦点传递给 iframe。

iframe 中可能成为焦点的任何内容都可以。

iframe.contentWindow.focus();

但是,iframe.contentWindow 不可访问,因为它是一个跨域框架。

【问题讨论】:

  • 你不能访问它
  • 如果你不控制iframe中的域,那么你就做不到。如果您确实控制了这两个域,那么您可以使用Window.postMessage() 在两者之间进行通信。这样您就可以在 iframe 中向页面发送消息,然后在 iframe 本身中设置焦点。

标签: javascript jquery google-chrome iframe cross-domain


【解决方案1】:

似乎答案是:不可能。

如果 iframe 中有脚本在运行,您可以直接从那里调用 focus。

【讨论】:

    猜你喜欢
    • 2012-08-01
    • 2011-12-28
    • 1970-01-01
    • 2010-09-27
    • 2016-12-06
    • 1970-01-01
    • 1970-01-01
    • 2011-06-09
    • 2017-07-19
    相关资源
    最近更新 更多