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 6 of 6
  1. #1
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,413
    Thanks
    268
    Thanked 32 Times in 31 Posts

    background color popup question

    Hi,

    I did find the information i needed in order to change the background color for a popup that i call for my images.

    However my issue is that it will only change the background color on the second time i execute it. So i have to open it twice before it will change the background. And im not sure why?

    here is the js function.

    Code:
    function popitpic(url) {
    	picwin=window.open(url,'popwin','location=0,status=0,scrollbars=1,directories=0,resizable=0,height=250,width=250');
    	picwin.moveTo(0,0);
                 picwin.document.body.bgColor="#100206";
    return false;  
    }//close function
    i am also not sure if i need the return false here in the function or in my image call anchor tag, does it really matter where it is as long as it is there?

    Thanks..
    Last edited by durangod; 06-24-2013 at 09:53 AM.

  • #2
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,413
    Thanks
    268
    Thanked 32 Times in 31 Posts
    any ideas on this one

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,198
    Thanks
    80
    Thanked 4,453 Times in 4,418 Posts
    Probably because the document hasn't finished loading when you try to change the color the first time. Maybe you need to check to see it it has loaded before attempting the color change? If it hasn't, do a timeout and check again in 50 milliseconds or so?

    ********

    If you are calling this form an <a> link, then you need to do either
    Code:
    <a href="something.jpg" onclick="return popitpic(this.href);">
    in which case, yes, popitpic needs to return false.

    Or you can do
    Code:
    <a href="something.jpg" onclick="popitpic(this.href); return false;">
    in which case, the return from popitpic is ignored.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,981
    Thanks
    56
    Thanked 557 Times in 554 Posts
    you can use the onload event of the window as long as you attach it (this is the only way I can get it to work, anyway) instead of the timeout approach:

    Code:
    function popitpic(url) {
    picwin=window.open(url,'popwin','location=0,status=0,scrollbars=1,directories=0,resizable=0,height=250,width=250');
    
    picwin[picwin.addEventListener ? 'addEventListener' : 'attachEvent'](
      (picwin.attachEvent ? 'on' : '') + 'load', function(){
    picwin.moveTo(0,0);
    picwin.document.body.bgColor="#100206";
      }, false
    );
    
    }

  • Users who have thanked xelawho for this post:

    durangod (06-28-2013)

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,198
    Thanks
    80
    Thanked 4,453 Times in 4,418 Posts
    LOL! Wow, is that sneaky code! I like it, but I would personally just do it more straightforward:
    Code:
    function popitpic(url) 
    {
        picwin=window.open( url, 'popwin', 
            'location=0,status=0,scrollbars=1,directories=0,resizable=0,height=250,width=250');
    
        if ( window.addEventListner )
        {
            picwin.addEventListener( "load", picwinload, false );
        } else {
            picwin.attachEvent( "onload", picwinload );
        }
        function picwinload( )
        {
            picwin.moveTo(0,0);
            picwin.document.body.bgColor="#100206";
        }
    }
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    durangod (06-28-2013)

  • #6
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,413
    Thanks
    268
    Thanked 32 Times in 31 Posts
    You both rock! thanks so much...


  •  

    Posting Permissions

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