Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript onblur event

Status
Not open for further replies.

theomen

Programmer
Jun 2, 2004
158
GB
Here's an annoying problem for you all.

I've got a fullscreen IE window launching a second window (automatically in fullscreen it seems). I need that second window to stay on top until the user fills in the form and submits it.

The first page has an onload event which checks whether the second window needs to be opened (this is in asp, so if a session variable called "evaluation_required" doesn't exist, then the javascript code isn't written). This then launches the new window.

The new window has an onblur event so that if the user uses alt-tab to go back to the opener, it will automatically give itself focus again, meaning they can't go back without closing the window (where there is also an onunload event to reload the original page). However, when I click into a textarea in the form, the page thinks its lost focus and takes the focus back from the textarea.

Stupidly, I then put an additional line of code into the onblur event to focus on the text area, but that crashed IE. I can now see why, because the page tries to get focus, then loses focus when it gives it to the textarea, at which point the onblur event kicks in again and goes into a continuous loop (at least I'm not sending emails this time, have sent 3000 emails in an infinite loop once, killed our email server :) ).

Can anyone advise me on what I could do to keep the focus on the evaluation form, but still allow focus on the textarea? I tried using a modal window, but had trouble submitting forms in that where it kept submitting to a new window.
 
i would suggest u use showModalDialog() method...

Known is handfull, Unknown is worldfull
 
Or, since you said you didn't like the results...

You could do this:

I assume your main window calls window.open(). Get the window object like this: var the_win = window.open(...). Then, have the body onfocus event of the main window do this:

if (the_win && !the_win.closed) {the_win.focus();}

*cLFlaVA
----------------------------
Breaking the habit...
 
vbkris,

I did try it, but had a couple of problems with it:

1) I couldn't get it to load in full screen. setting it to screen.height and screen.width set it to full page, but I still had the titlebar

2) When submitting the form, it submitted to a new window rather than itself. I tried putting "target=this" in the form header, which didn't work.


cLFlaVA, I did try that earlier and can't remember what went wrong. will try it again though because it might have been something else which broke and which I have now removed. I think it also went into a loop.
 
cLFlaVA,

Just tried your method, and realised what the problem was when I tried it earlier.

The first time I do an Alt-Tab, it works fine, the onfocus event on the main window gives the focus back to the new window.

However, when I do it again it doesn't work.

Now the weird bit, if I do it again (without closing the new window at all by this point), it works, then it doesn't, and so on. So it only works on alternate alt-tab's.
 
i think there is also a createPopup method...

Known is handfull, Unknown is worldfull
 
Onblur generally sucks - in many cases it can be replaced with onchange (but not here) or onactivate/ondeactivate (IE only).

createPopup() disappears after you click somewhere else :(

You can use IFRAME inside modal dialog, though this is pain for debugging.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top