Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: Popup code

  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Popup code

    Hi all, I'm currently using this bit of code for image popups, basically so I don't have to create an individual page for each one. It works fine, however it keeps open each popup when you open another one. Is there anyway anyone could tweak the code so that when a new popup opens, it closes the previous one first. For example, when I click a link to get a popup, this currently stays open unless you physically close the window, what I need is when you click on another link for a different popup, the previous one is closed and over-ridden by the current one.

    function popimage(imagesrc,winwidth,winheight,winsb){
    var look='width='+winwidth+',height='+winheight+',scrollbars='+winsb+' ,'
    popwin=window.open("","",look)
    popwin.document.open()
    popwin.document.write('<title>Popup</title><body topmargin=0 leftmargin=0 marginwidth=0 marginheight=0><img src="'+imagesrc+'"></body>')
    popwin.document.close()
    }

    Thanks in advance

    Chris

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    197
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think you can use something like
    opener.close();

    ez
    Animation Rule #64
    Poor quality images are often artistic,
    Poor quality sound is ALWAYS annoying.

  • #3
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Really, it's as simple as naming your window.

    Use window.open("", "windowname", look);

    This window will be reused if it is available, and created if it is not.

  • #4
    New Coder
    Join Date
    Jun 2002
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks guys.

    My link currently looks like this:

    <a href="#" onClick="popimage('images/contracts-pop-image1.jpg',550,367,0);return false">

    How would I implement said change into this??

    Thanks

    Chris

  • #5
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    popwin=window.open('','winName',look);

    would go inside your function where it now reads

    popwin=window.open('','',look);

  • #6
    New Coder
    Join Date
    Jun 2002
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ahh, I get it, thanks for that, it does work now, however there are a couple of problems.

    The first is that the popup does get replaced, but it stays at the bottom of the screen minimized and doesn't pop back up?

    The second is some of the popup images are different sizes and I would like it to resize these rather than just overlay in the previous popup window.

    Thanks.

    Chris

  • #7
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Gotcha.

    Add this before you open popwin:

    Code:
    if (popwin) {
         try{
             popwin.close();
         } catch(e) {
             ignore="this error";
         }
    }
    That might work. If not, outside your function declare
    Code:
    var popwin;
    and that will help.

    What's your target audience? (Browser type, version, etc)

  • #8
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    This covers everything. popwin.resize takes care of resizing. window.focus makes it show up on top every time.


    <html>
    <head>
    <script>
    function popimage(imagesrc,winwidth,winheight,winsb){
    var look='width='+winwidth+',height='+winheight+',scrollbars='+winsb+' ,';
    popwin=window.open("","mypop",look);
    popwin.document.open();
    popwin.resizeTo(winwidth, winheight);
    popwin.document.write('<title>Popup</title><body onload="window.focus()" topmargin=0 leftmargin=0 marginwidth=0 marginheight=0><img src="'+imagesrc+'"></body>');
    popwin.document.close();
    }
    </script>
    </head>
    <body>



    <a href="#" onClick="popimage('map.gif',425,511,0);return false">1</a>
    <a href="#" onClick="popimage('mapquest.gif',400,400,0);return false">2</a>
    <a href="#" onClick="popimage('mapvr1.gif',390,390,0);return false">3</a>
    <a href="#" onClick="popimage('bo030611.gif',600,197,0);return false">4</a>

    </body>
    </html>

  • #9
    New Coder
    Join Date
    Jun 2002
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That's the baby, works like a treat, thanks Choopernickel and arnyinc, very much appreciated.


    Chris


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •