Javascript: Keeping popup window always on top

I was looking for a solution  (that does not involve proprietary modal dialogs) that would allow to open a popup window in JavaScript and keep it “always on top” of the opener, meaning – when user clicks outside of the popup – the popup retakes focus.
Commonly suggested solution:

<body onblur="this.focus()">

didn’t work for me since I have a form in that popup with input fields and the moment user clicks a field, popup itself loses focus, retakes it right away and user is unable to enter any data.
Fortunately I found an ingenious solution by Jim Allen that involves combination of timer-activated focus that in the same time is controlled by form’s input controls. That sounds complicated 🙂 but in fact is just a few lines of code. Check it out!

Leave a Reply

Your email address will not be published. Required fields are marked *