popup window script won't work with a space in the window name.

Discussion in 'JavaScript' started by wolfestone, Feb 16, 2009.

  1. #1
    I'm using the following script, and it's working fine except when my aWinName (the new window's title bar text) has a space in it. I've tried using %20, and also   but both of these cause the window to not appear. If I use a single word for the window title it works fine.

    I'd really appreciate it if anyone can tell me either a workaround, or how to modify the script so it'll work with a space in the aWinName parameter.

    here's the code:

    function f_open_window_max( aURL, aWinName )
    {
       var wOpen;
       var sOptions;
    
       sOptions = 'status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes';
       sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
       sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString();
       sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';
    
       wOpen = window.open( '', aWinName, sOptions );
       wOpen.location = aURL;
       wOpen.focus();
       wOpen.moveTo( 0, 0 );
       wOpen.resizeTo( screen.availWidth, screen.availHeight );
       return wOpen;
    }
    
    Code (markup):
    And here's how I'm calling it from my html - the space between Page and One is what stops it working:

    <a href="#"><img src="images/myImage" width="200"  border="0"
    onclick="f_open('pages/page.htm','Page One')" /></a>
    
    Code (markup):

     
    wolfestone, Feb 16, 2009 IP
  2. dilute

    dilute Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    the window name is designed for accessing the window, not setting the title text.

    Use:

    function f_open_window_max( aURL, aWinName, aTitleText)

    then after: wOpen.location = aURL;
    put: wOpen.document.title = aTitleText;

    if that doesn't work try wOpen.title without the "document" part.

    Then call it with onclick="f_open('pages/page.htm','pageone', 'Page One')"
     
    dilute, Feb 16, 2009 IP
  3. wolfestone

    wolfestone Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    awesome, thanks very much!
     
    wolfestone, Feb 17, 2009 IP
  4. dilute

    dilute Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Rep me. Click the [​IMG]
     
    dilute, Feb 17, 2009 IP