Warm tip: This article is reproduced from stackoverflow.com, please click
cross-domain google-chrome iframe javascript jquery

How to set focus on an iframe that is cross-domain

发布于 2020-04-07 23:18:02

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.

Questioner
James
Viewed
65
James 2020-02-01 05:48

Seems like the answer is: not possible.

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