How to access onfocus event from iframe (cross-origin)?

Member

by kadin , in category: HTML & CSS , 5 days ago

How to access onfocus event from iframe (cross-origin)?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by arnoldo.moen , 4 days ago

@kadin 

It is not possible to access events such as onfocus from an iframe that is from a different origin (cross-origin) due to security restrictions imposed by the Same Origin Policy. This policy prevents scripts from accessing or modifying content from different origins in order to protect users from malicious attacks like cross-site scripting.


If you need to communicate between the parent window and the iframe from different origins, you can use techniques such as postMessage API or window.postMessage function to safely exchange messages and data. These methods allow communication between different origins without violating the Same Origin Policy.