#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    105
    Rep Power
    11

    Simple Javascript PopUp


    Here's the original code I'm playing with :

    Code:
    <SCRIPT TYPE="text/javascript">
    <!--
    function popup(mylink, windowname)
    {
    if (! window.focus)return true;
    var href;
    if (typeof(mylink) == 'string')
       href=mylink;
    else
    href=mylink.href;
    window.open(href, windowname, 'width=400,height=200,scrollbars=no');
    return false;
    }
    //-->
    </SCRIPT>
    The href contains the link (dah) and the window name... Like so : <A HREF="popup_test_a.html" onClick="return popup(this,'example')">this link</A>

    I want to add some code so that according to the windowname, the javascript opens the link in another windows, but, with different width and height...

    Is there something else I could add in the "popup(this,'example','test')" and add an If/Else in the code ?
  2. #2
  3. recovering whitewater addict
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Location
    Lexington, you guess the state
    Posts
    269
    Rep Power
    14
    Sure, just change the function to something like:
    Code:
    function popup(mylink, windowname, windowWidth, windowHeight)
    Then change your window.open call to:
    Code:
    window.open(href, windowname, 'width=' + windowWidth + ', window,height=' + windowHeight + ', ascrollbars=no');
    use your numbers you want when you call the function and add if / else blocks as appropriate.
    Friends help you move...
    real friends help you move bodies.
  4. #3
  5. Application is what Divides Us
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Dec 2002
    Location
    Titusville, FL
    Posts
    2,179
    Rep Power
    59
    This would make customizing each window, much much, easier

    Code:
    <script type='text/javascript'>
    <!--
    
    function pop(wLoc, wName, wProp){
      var nWin = window.open(wLoc, wName, wProp);
      if (nWin.focus){ nWin.focus(); }
    }
    
    // <a href='http://www.domain.com/'
    //    onclick="return !pop(this.href, 'Domain', 'top=1,left=1,width=800,height=600');">Domain.com</a>
    
    //-->
    </script>

    Comments on this post

    • hanleyk1 agrees : Cool approach. I like it.
    Download [ Fx | Op ] Validate [ Markup | Css ]

IMN logo majestic logo threadwatch logo seochat tools logo