You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Rønnevik, Eivind <ei...@kadme.com> on 2006/10/17 08:43:00 UTC

How to respect / limit number of simultanously javascript popups allowed

Hi!

To be short, I have a <h:dataTable> filled by values from a list.

For each row/item the user can press a "view details" button, which opens a popup with the javascript-function window.open(). The user is also given the possibility to open several popups at a time to provide support for comparing to or more rows to each other (the names of the popups are unique).

My "challenge" is that I need a way to set and respect a limit of number of popups allowed. My commandLinks should render differently based on this condition. 

if (currentNumberOfPopups < popupLimit)
commandLink opens a new popup window with row details

if (currentNumberOfPopups >= popupLimit)
commandLink opens a popup saying that the popupLimit has been reached.

If limit is reached and the user close one of the existing popup windows, it should be possible to open new popups. The condition set on the commandLinks therefore enforces a refresh of my parent page whenever a new popup is created or if a popup is closed. If the limit is reached the user is also presented with an error message on top of the parent page.

Ok, and this is what I've tried to do so far:

I have a bean with a HashMap and the attributes currentNumberOfPopups and popupLimit (both ints). When I open a new popup I put a reference of it into the HashMap, thus keeping track of the popups that are opened (and the number of popups of course). I also execute a javascript function that clicks a hidden button in my parent page, and this button is implemented with ajax a4j to refresh the view to be up to date with the changes.

To handle the closing of a popup I have an unload event that fires only if users have pressed the 'X' button or if they have pressed a "close" commandButtoon. (to manage this I had to go for an IE only solution, but i'm okay with that for now). A refresh of the page does not fire this event. This event basically removes the reference from the HashMap, and then clicks the same refresh-button as was clicked when opening.

My problem is:
This way of doing it doesn't seem to be "accurate" enough. Sometimes (for no reason) the parent view doesn't refresh as it should (commandLinks are'nt updated), and I've also experienced that my counter gets out of sync with the actual number of popups open. This results in the error-popup to be opened when it shouldn't have been opened. 

Does anybody see another/a better way of handling this? How to respect a popup limit? Any ideas / new approaches would have been appreciated. I've been thinking of having a global array in javascript that holds the handlers to the popup-windows, and then somehow manage the rendering based on the size of this array, but the problem is that when I refresh the parent page this array is reset as well, so I cannot go down that path. 

Regards,

Eivind

 
 

Re: How to respect / limit number of simultanously javascript popups allowed

Posted by Kevin Galligan <kg...@gmail.com>.
I'd suggest doing this (if absolutely necessary, because it seems clunky) in
your javascript code on the front end.  Why?  Browsers tend to allow popups
for a site if they are triggered by a user event (button click, for example)
rather than when the page opens (porn ad).

In the onclick, have a funciton that keeps count.  When you have your max,
just pop up an alert box (rather than another window).

When the user closes a window, in the 'onunload', call opener.[your js
function].  You might have to call 'opener.document.[your js function]'.
One of them will work.  Anyway, in this function, just free up one of the
windows.

I'd second the div suggestion, or you could open a single long window with
these values side by side, if you want to compare them.

Have a page refresh and non-event popups is asking for headaches.

On 10/17/06, David Delbecq <de...@oma.be> wrote:
>
> Rønnevik a écrit :
> > Hi!
> Hi
> >
> > Does anybody see another/a better way of handling this? How to respect a
> popup limit? Any ideas / new approaches would have been appreciated. I've
> been thinking of having a global array in javascript that holds the handlers
> to the popup-windows, and then somehow manage the rendering based on the
> size of this array, but the problem is that when I refresh the parent page
> this array is reset as well, so I cannot go down that path.
> >
> Couldn't you do one of those simpler solutions?
>
> 1) don't care about number of popups (fast, easy, but sometimes the
> client want ... strange specifications like popup limitations)
> 2) Have your application cycle amongst popup names (popup-1, popup-2,
> ...), this way, when you click, you just select the next name. No need
> to handle popups states in hashmap and play with onload. If popup was
> closed, it will be reopen, else, it will have the new content)
> 3) Handle you popup as draggable DIV inside main window. This is a bit
> of work and might not meet gui requirements, but at least the only way
> user can close the DIV is clicking the [X] button.
> > Regards,
> >
> > Eivind
> >
> >
> >
> >
>
>

Re: How to respect / limit number of simultanously javascript popups allowed

Posted by David Delbecq <de...@oma.be>.
Rønnevik a écrit :
> Hi!
Hi
>
> Does anybody see another/a better way of handling this? How to respect a popup limit? Any ideas / new approaches would have been appreciated. I've been thinking of having a global array in javascript that holds the handlers to the popup-windows, and then somehow manage the rendering based on the size of this array, but the problem is that when I refresh the parent page this array is reset as well, so I cannot go down that path. 
>   
Couldn't you do one of those simpler solutions?

1) don't care about number of popups (fast, easy, but sometimes the
client want ... strange specifications like popup limitations)
2) Have your application cycle amongst popup names (popup-1, popup-2,
...), this way, when you click, you just select the next name. No need
to handle popups states in hashmap and play with onload. If popup was
closed, it will be reopen, else, it will have the new content)
3) Handle you popup as draggable DIV inside main window. This is a bit
of work and might not meet gui requirements, but at least the only way
user can close the DIV is clicking the [X] button.
> Regards,
>
> Eivind
>
>  
>  
>