1

Similar to the posts below:

  1. Set focus on iframe in Chrome

  2. Setting focus to iframe contents

From the root/parent I want to be able to pass focus to the iframe.

Anything that may be in focus in the iframe is fine.

iframe.contentWindow.focus();

However, the iframe.contentWindow is not accessible because its a cross-origin frame.

James
  • 2,742
  • 1
  • 20
  • 43
  • You can not access it – epascarello Jan 31 '20 at 20:17
  • If you don't control the domain in the iframe, then you cannot do it. If you do control both domains, then you could communicate between the two using [Window.postMessage()](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage). This way you could send a message to the page in iframe and then set the focus in the iframe itself. – Bojan Bedrač Jan 31 '20 at 21:25

1 Answers1

1

Seems like the answer is: not possible.

If there is a script running in the iframe you can directly call focus from there.

James
  • 2,742
  • 1
  • 20
  • 43