You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Nick Tonkin <ni...@rlnt.net> on 2001/11/20 19:21:07 UTC

[OT] Re: How to create a browser popup window

Off topic but in the interests of, if not less popup windows, then at
least less broken ones:

You must include code to deal with the fact that you may have already
opened a popup window. Something like this:

    <SCRIPT LANGUAGE="JavaScript">
      <!-- Hide
        var popupwin = null;
        function popup(loc,ww,hh) {
          var mywidth = (ww + 10);
          var myheight = (hh + 10);
          var myspecs = "'menubar=1,status=1,resizable=1,location=1,titlebar=1,toolbar=1,scrollbars=1,width=" + mywidth + ",height=" + myheight + "'";
          
          if (popupwin == null || popupwin.closed) {
            popupwin = window.open (loc, 'popupwin', myspecs);
          } else {
            popupwin.close();
            popupwin = window.open (loc, 'popupwin', myspecs);
            
            // If all your windows should be the same
            // size then comment out the above two lines and
            // uncomment the next two lines

            //  popupwin.focus();
            //  popupwin.location.href = loc;
          }
        }
    </SCRIPT>

    <A HREF='javascript://' onClick='popup("foo.gif",300,200); '>Look at foo</A>



This one is good for calling with just an image as the href. You can use
any code you like, including the other example posted here. Just remember
to test whether you already have the window open or not and act
appropriately.


~~~~~~~~~~~
Nick Tonkin

On Tue, 20 Nov 2001, Ben Demonte wrote:

> How to create a browser popup windowhow do I unsubscribe from this list.
> 
>   ----- Original Message ----- 
>   From: Domien Bakker 
>   To: modperl@apache.org 
>   Sent: Tuesday, November 20, 2001 6:30 AM
>   Subject: How to create a browser popup window
> 
> 
>   Hello all, 
> 
>   Can anybody give me the "golden" tip of creating a popup browser window 
>   from my mod_perl handler? I want to fill in this popup window with results 
>   generated within my handler. 
> 
>    Is there a module available from CPAN which can handle this? 
> 
>   Thanks in advance! 
> 
>   Met vriendelijke groet / With kind regards, 
>   Domien Bakker 
>   Application Developer 
> 
>   Application development 
>   Operations and Engineering 
>   ZeelandNet BV 
> 
>   Postbus 35 
>   4493 ZG Kamperland 
>   The Netherlands 
>   tel. +31 (0)113 377733 
>   fax +31 (0)113 377784 
>   domien@staff.zeelandnet.nl 
>   http://ww.zeelandnet.nl/ 
> 
> 
> 
> 
> 


[OT] Re: How to create a browser popup window

Posted by Nick Tonkin <ni...@rlnt.net>.
On Tue, 20 Nov 2001, Rob Bloodgood wrote:

> > You must include code to deal with the fact that you may have already
> > opened a popup window. Something like this:
> 
> That is simply not true.  window.open() with a named window ('popupwin', in
> your example) ALWAYS reuses that window, on every browser I've ever been
> able to test.

I didn't say duplicate windows was the problem. The problems are:

1) If the window exists it may have lost focus.
2) If the window exists you cannot resize it (eg for displaying full-size
images from thumbnails, etc.)

> A corrected version of your sample script follows.  It's much simpler now...

So simple it only does half of what it did :)

</THREAD> ?


- nick


RE: [OT] Re: How to create a browser popup window

Posted by Rob Bloodgood <ro...@empire2.com>.
> You must include code to deal with the fact that you may have already
> opened a popup window. Something like this:

That is simply not true.  window.open() with a named window ('popupwin', in
your example) ALWAYS reuses that window, on every browser I've ever been
able to test.  The second call to window.open, with a new URL, simply
refreshes the contents of the popup w/ the new URL.  Note, this is *only*
true for named windows.  Windows without a window name string as the second
parameter to window.open() will open a new window every time.

It can, however, be a good idea to explicitly call focus() on your child
window, because in the situation I've just mentioned, if the child window's
url is refreshed, it is NOT automatically brought to the foreground.

The original post was wondering how to put mod_perl output in a popup
window.  The answer is simply top call window.open() with the URL of the
mod_perl handler as its location.

If one is trying to be "responsible" about the window(s) being open, adding
a link like

<a href="javascript:window.close()">CLICK HERE CLOSE THIS WINDOW</a>

in the child window is usually reasonably simple for the user to understand.
Of course, the normal caveats about users understanding something still
apply...

A corrected version of your sample script follows.  It's much simpler now...
:-)

>     <SCRIPT LANGUAGE="JavaScript">
>       <!-- Hide
>         var popupwin = null;
>         function popup(loc,ww,hh) {
>           var mywidth = (ww + 10);
>           var myheight = (hh + 10);
>           var myspecs =
> "'menubar=1,status=1,resizable=1,location=1,titlebar=1,toolbar=1,
> scrollbars=1,width=" + mywidth + ",height=" + myheight + "'";
>
>             popupwin = window.open (loc, 'popupwin', myspecs);
>		  popupwin.focus();
>         }
>     </SCRIPT>

>  <A HREF='javascript:' onClick='popup("foo.gif",300,200)'>Look at foo</A>


L8r,
Rob
#!/usr/bin/perl -w
use Disclaimer qw/:standard/;