SitePoint Sponsor

User Tag List

Results 1 to 14 of 14

Thread: Window.open

  1. #1
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Window.open

    I've been using the following code to open new windows:

    <script launguage="javascript">
    function openWindow(url)
    { window.open(url,'newpage','scrollbars=no,resizable=no,width=400,height=200');
    }


    <html>
    ....
    .....
    <a href="javascriptpenWindow(php/newsregister.php');">Click here</a>
    ...
    ...
    </html>


    My question is i cant seem to get it working so i can specify the size. i.e. i want to create a function

    function openWindow(url,width,height)

    Can i do this? I have tried google. Sorry if the answer is obvious. I have tried a few things

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,441
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    variables

    Did you try something like
    HTML Code:
    window.open(url,'newpage','scrollbars=no,resizable=no,width=' + width + ',height=' + height + ');

  3. #3
    SitePoint Member
    Join Date
    Dec 2001
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you just have a simple typo. In your call to the function, the parameter needs to be quoted, and you're missing the first quote. It should be:

    Code HTML4Strict:
     <a href="javascript:openWindow('php/newsregister.php');">Click here</a>

  4. #4
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    Did you try something like
    HTML Code:
    window.open(url,'newpage','scrollbars=no,resizable=no,width=' + width + ',height=' + height + ');
    I did. Cant think of what to try. This is all that needs finishing on site.

  5. #5
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by desr333 View Post
    I think you just have a simple typo. In your call to the function, the parameter needs to be quoted, and you're missing the first quote. It should be:

    Code HTML4Strict:
     <a href="javascript:openWindow('php/newsregister.php');">Click here</a>
    sorry ye i just copied it across wrong. It works if i set the size in the function and then just call it therefore giving a set size window every time

    What i want is to specify in the actual call to the function the size the window should be

  6. #6
    SitePoint Member
    Join Date
    Dec 2001
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ahh, well in that case, try this:

    Code JavaScript:
    function openWindow(url, width, height)
    { 
    winSettings='scrollbars=no,resizable=no,width=' + width + ',height=' + height;
    window.open(url,'newpage',winSettings);
    }

    Code HTML4Strict:
    <a href="javascript:openWindow('http://www.socsci.uci.edu', 300, 200);">Click here</a>

  7. #7
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    fantastic! exactly what i needed it to do. Thankyou very much for your help. You've just solved something for me i've been struggling with on and off for a couple of days.

  8. #8
    SitePoint Member
    Join Date
    Dec 2001
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem, glad I could help. happy javascripting!

  9. #9
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i've come across an aditional problem. I have two links which open popups. Both are different sizes. With this code if i have the small one open and click the second link it opens up inside the already open smal window and therefore doesnt show all the content as its not big enough. Is there a way around this? Can i force it to open an additional window?

  10. #10
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,441
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    2 windows

    Give them different names.

  11. #11
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    to save file sizes i've tried to limit my javascript. I'm using one function for opening popups as on another page there will be 7 different popups with different sizes.

    if using one function doesnt allow me to open different pages for each one can i at least force the already open page to resize rather than keep the old size?

  12. #12
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually could i specify the window name in the call to the function if i rewrote the function to accommodate?

  13. #13
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the idea Mittineague. just tried it and created a new function with an additional parameter. perfect! Thanks again

  14. #14
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can i also force the windows to stay in focus and not get lost behind the rest?


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
  •