0

My issue here is that I am loading an iframe on top of my current window. When I hide this iFrame, I need the focus to be given back to the original window that opened the iFrame so that it can detect keyboard strokes.

My idea is to grab the element that currently has focus before opening the iFrame, and then give it back the focus when the iframe is closed.

I have tried doing window.focus() and top.window.focus() but it does not seem to work.

Dave McGregor
  • 89
  • 1
  • 6
  • What browser are you using? – adam0101 Jan 20 '15 at 14:09
  • Take a look at http://stackoverflow.com/questions/2758608/window-focus-not-working-in-google-chrome – adam0101 Jan 20 '15 at 14:12
  • Looks like Chrome is a known issue. I'm curious if maybe `top.window.name = "myWindow"; top.window.open('', 'myWindow');` would work for you. Otherwise, an `alert('')` might do the trick if that's an option. – adam0101 Jan 20 '15 at 14:18
  • If there is an input element in your parent window, do a document.getElementById('yourInputID').focus(); where the yourInputID is the ID of the element. If you are calling from within iframe, do a parent.document.getElementById('yourInputID').focus(); instead. Run this after hiding the iframe. Hope this helps! – webtrick101 Jan 21 '15 at 09:11

0 Answers0