【问题标题】:How to set focus for #document in iframe using javascript如何使用javascript在iframe中为#document设置焦点
【发布时间】:2020-06-17 08:53:28
【问题描述】:

如何使用 javascript 将焦点设置到 iframe 内的#document?

尝试了下面的代码,但没有工作

  document.getElementById('iframe').focus()

【问题讨论】:

  • 这能回答你的问题吗? Setting focus to iframe contents
  • 不。我仍然没有集中注意力。我特别想关注文档正文 this.AppLaunchEl.contentWindow.document.body.focus() 我也尝试过 this.AppLaunchEl.contentWindow.document.focus()
  • 但是你是否等待页面重新加载 $(document).ready(// 你的函数) @KadeejaBai
  • 在这种情况下我不能使用 jQuery 方法,所以我没有检查它。加载 iframe 后,我尝试等待一段时间

标签: javascript html iframe focus


【解决方案1】:

你可以这样做:

  var iframe = document.getElementById("myFrame");
  var elmnt = iframe.contentWindow.document.getElementById("elementId");
  elmnt.focus();

【讨论】:

  • 元素体每次都不一样,不能用。
猜你喜欢
  • 1970-01-01
  • 2021-04-20
  • 2010-09-27
  • 1970-01-01
  • 2011-12-28
  • 2020-05-17
  • 1970-01-01
  • 2010-12-03
  • 2013-07-13
相关资源
最近更新 更多