PDA

View Full Version : Close Pop-Up if user goes to another window.



REHAKES
08-09-2006, 04:39 PM
I have server-side script that pops up after the user submits a form. It's basically telling the user if there's a problem with the data submitted or not.

the user is given a message, and presented with two buttons, "Go Back", which does an onClick="window.close()"

And a "Next Step" which does onClick="window('http://...and the URL to the next page.

Everything works OK, but when the user chooses to go to the next window, the one he was in stays open, unless he manually closes it.

I tried using a dummy <INPUT TYPE="Image" src="transparent. gif" onBlur="window.close()"> and it didn't work. Probbly because there was no text area to gain focus, and hence focus to be lost.

Does anybody have an idea on how to get un-needed pop-ups to close automatically, if the user leaves that window?

Thanks.

jscheuer1
08-10-2006, 09:23 AM
Well, as you probably know, a window that wasn't opened by javascript cannot be reliably closed with javascript. If that isn't an issue here, any window opened by javascript can be made to close when it loses focus. I don't know if that will fit the situation you have, as your description is a little sketchy but, here's how - Just put a script like so in the head of the page:


<script type="text/javascript">
window.onblur=function(){self.close();};
</script>

mwinter
08-10-2006, 02:03 PM
window.onblur=function(){self.close();};

I don't know if you've ever been on the receiving end of code like that John, but I can assure you that it's a pain in the ass.

More often than not, I've encountered things like this in image galleries. Larger images open in pop-ups that I never asked for (bad enough in itself), and close automatically if they lose focus.

As a dial-up user, I'm not about to sit around twiddling my thumbs waiting for an image to load. However, to not do so means that the image closes. I'm now either forced to wait, or (in Firefox) select View Image from the context menu and replace the pop-up contents (including that annoying code) with solely the image.

There are, of course, other reasons why the window might lose focus. A background application might come to the foreground to indicate that it's finished or has encountered a problem. The operating system might do the same should a critical event occur. In any of these cases, it is not the user's intention to implicitly signal the end of a pop-up's use. In fact, they might not even have had time to read its contents.

Modern operating systems are multitasking, and applications should be written with this fact in mind and behave themselves. By all means, close a pop-up in direct response to a user-initiated action, but don't try to guess what the user is doing. Ideally though, the OP would find a way to drop the pop-up entirely (at least if this is for the Web): one shouldn't assume that pop-ups will be accepted by the user.

Mike

jscheuer1
08-10-2006, 05:30 PM
I don't know if you've ever been on the receiving end of code like that John, but I can assure you that it's a pain in the ass.

Although the rest of your post raises some indisputably valid points, the above quoted is a bit absolute in that it doesn't take into consideration the details of the setup, in response:

I have and it hasn't been (a pain in the . . .) for me. However, I have a high speed connection. I've even written a gallery or so with exactly what you are talking about except that it is known to the user that clicking will retrieve the larger image so, it's not "not even asked for" and the 'larger image' isn't overwhelmingly large, about 8K. As for the OS or a BG ap interfering (which would interfere with even the simplest foreground task, web surfing aside), just open the pop up again.

In support of my initial assertion that you raise some valid points:

If this isn't practical for the OP, that would be the OP's job to decide. Your input certainly should help them in that decision making process as their pop up might not play well if it were to be dismissed inadvertently. However, this (close onblur) appears to be just what he/she was shooting for, albeit perhaps ill advised.

The most important consideration here is probably - what if the user has pop ups blocked? In the case of the type of gallery I am talking about, where the focus of the site happens to be information and the gallery is just a side show to begin with, if you cannot access the big pictures in the photo gallery, you will just have to make due with the thumbs which are adequate for conveying the information. The larger images are just extra.

But, if filling out a station in a series of forms that are critical for one reason or another, the pop up wouldn't be appropriate to begin with.

mwinter
08-10-2006, 07:55 PM
Although the rest of your post raises some indisputably valid points, the above quoted is a bit absolute

That's because it was absolute. :)



in that it doesn't take into consideration the details of the setup ...

The details are quite irrelevant as the facts remain the same: it is not possible to ascertain why the pop-up lost focus, therefore to automatically close it is guaranteed to be the wrong thing to do in at least some cases.



I have and it hasn't been (a pain in the . . .) for me. However, I have a high speed connection.

That's not really the issue, though the wait induced by dial-up does magnify the problem. Users of tabbed browsers should be able to utilise that capability to the full. Rather than load a single image at a time, load several in the background and move on to the next gallery. Again, requiring focus prevents this.



As for the OS or a BG ap interfering (which would interfere with even the simplest foreground task, web surfing aside),

Yes, it would. However, it doesn't close an application, or cancel whatever the user was doing, does it? That's what can happen here.



just open the pop up again.

In some cases that's an option, of course, but if the author didn't fiddle in the first place, it would be unnecessary.

From the description supplied by the OP, the pop-up is created as a function of submitting a form. That implies that it is a one-time event. If so, closing the pop-up would be irreversible.

Mike

jscheuer1
08-11-2006, 03:09 AM
From the description supplied by the OP, the pop-up is created as a function of submitting a form. That implies that it is a one-time event. If so, closing the pop-up would be irreversible.

Having it blocked in the first place would be a bad deal too.

I think we agree on more of this than your most recent reply would at first make it appear. In any case, I think we agree on the above quote and my immediate comment after it. This is really the paramount consideration here. If the situation is otherwise, like if the form isn't so critical or it really isn't a form, etc. then there would probably be little harm but if, as we both suspect, it is an important form - then the OP shouldn't be using a pop up to begin with.

REHAKES
08-11-2006, 09:51 AM
:) Thanks for the posts, folks! The discussion ranged a bit, but all the points made were valid; even those that didn't directly address the original issue.

That's what's so neat about this place!

Bob