0

How to set focus to #document inside an iframe using javascript ?

enter image description here

Tried the below code but not working

  document.getElementById('iframe').focus()
  • Does this answer your question? [Setting focus to iframe contents](https://stackoverflow.com/questions/369026/setting-focus-to-iframe-contents) – Jack hardcastle Jun 17 '20 at 08:56
  • No.I'm still not getting focus. I specifically want to focus on the document body this.AppLaunchEl.contentWindow.document.body.focus() i have also tried this.AppLaunchEl.contentWindow.document.focus() – Kadeeja Bai Jun 17 '20 at 08:57
  • But did you wait for the page to reload $(document).ready(// your functions) @KadeejaBai – Sachin Yadav Jun 17 '20 at 09:09
  • I cant use jQuery methods in this case so I haven't checked it. I have tried waiting for a while after the iframe is loaded – Kadeeja Bai Jun 17 '20 at 09:19

1 Answers1

0

You can do something like this:

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