SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist JordashTalon's Avatar
    Join Date
    Dec 2008
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Window.open() Problems

    I have some code like this as part as a function

    NewWindow=window.open('+url+','Form','width='+PWidth+',height='+PHeight+',left=100,top=100,toolbar=No,location=No,scrollbars=Yes,status=No,resizable=Yes,fullscreen=No');

    The window PopsUp but it says 'Page Cannot be Found,

    When I do it like this though

    NewWindow=window.open('http://linktopage','Form','width='+PWidth+',height='+PHeight+',left=100,top=100,toolbar=No,location=No,scrollbars=Yes,status=No,resizable=Yes,fullscreen=No');

    It works just fine

    for some reason when I try and pass in the URL through the function it doesn't work but when I insert the link directly into the window.open() function it works
    (even when the URL's are exactly the same)

    Any idea whats going on?

    The PWidth and the PHeight Variables work right.

    Full Code:

    Code:
    <SCRIPT>
    function popUp(page,PWidth,PHeight,id,url) {
    
    NewWindow=window.open('+url+','Form','width='+PWidth+',height='+PHeight+',left=100,top=100,toolbar=No,location=No,scrollbars=Yes,status=No,resizable=Yes,fullscreen=No');  NewWindow.focus();      
    void(0);
    
    }
    
    </SCRIPT>
    HTML

    Code:
    <a href="javascript:popUp('form', 800, 650, 10, 'http://multicultural.byu.edu/PHP/soarapp/soarformattach.php')">Text</a>

  2. #2
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use url instead of '+url+':
    Code:
    <SCRIPT>
    function popUp(page,PWidth,PHeight,id,url) {
    
    NewWindow=window.open(url,'Form','width='+PWidth+',height='+PHeight+',left=100,top=100,toolbar=No,location=No,scrollbars=Yes,status=No,resizable=Yes,fullscreen=No');  NewWindow.focus();      
    void(0);
    
    }
    
    </SCRIPT>
    I'm creating trouble-free Apache, PHP, MySQL installer, WITSuite,
    and use it to setup my development environment.
    Demo, support, contact. Questions?

  3. #3
    SitePoint Evangelist JordashTalon's Avatar
    Join Date
    Dec 2008
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, just out of curiosity why did the PWidth and Pheight need the + stuff?

  4. #4
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because third parameters of the window.open should be string with pairs key=value separated by commas. By injecting '+variable+' construction you place the value of the variable in the string.

    Actually, you can use ''+url+'' in the first parameter too, but it does not make sense.
    I'm creating trouble-free Apache, PHP, MySQL installer, WITSuite,
    and use it to setup my development environment.
    Demo, support, contact. Questions?


Bookmarks

Posting Permissions

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