Close

Results 1 to 5 of 5
  1. #1
    DF VIP Member big man's Avatar
    Join Date
    Jul 2002
    Location
    The big smoke
    Posts
    2,824
    Thanks
    8
    Thanked:        0
    Karma Level
    445

    Open window using Java

    Hi guys

    I'm having a problem opening a child window using javascript

    what I need to do is to open the new window, centered on the screen, no matter what the users resolution.

    I've done a bit of code that works in IE, but when it runs in Netscape or IE on a Mac, it will center vertically, but nor horizontally.

    PHP Code:
        function newWindow() {
        var 
    left = (screen.width 2) - 350
        
    var top = (screen.height 2) - 250
            window
    .open("main.html","","width=700,height=499, top="+top+", left = "+left+"")
        } 
    Any help appreciated

    Big man
    I am a loud man with a very large hat. This means I am in charge

    Never argue with an idiot. They will bring you down to their level, then beat you with experience.

  2. #2
    DF VIP Member WTD's Avatar
    Join Date
    Mar 2001
    Location
    Tokyo, Japan
    Posts
    3,256
    Thanks
    0
    Thanked:        0
    Karma Level
    492

    Default

    Its the way that netscape deals with positioning mate.
    In the settings variable that you are using to declare window features, there is one difference between browsers. IE uses top= and left= but Netscape uses screenX= and screenY= -- so you need to list both to catch all browsers.

    Code:
    function NewWindow(mypage,myname,w,h,scroll,resize){ 
    
    < !-- if browser is IE //-- > 
    if (document.all){ 
    LeftPosition = (screen.width)? (screen.width-w)/2 : 0; 
    TopPosition = (screen.height)? (screen.height-h)/2 : 0; 
    
    settings = 
    'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable='+resize+',status' 
    
    window.open(mypage,myname,settings) 
    
    } 
    < !-- browser = NS6 //-- > 
    else { 
    
    LeftPosition = (screen.width)? (screen.width-w)/2 : 0; 
    TopPosition = (screen.height)? (screen.height-h)/2 : 0; 
    
    settings = 
    'height='+h+',width='+w+',screenX='+TopPosition+',screenY='+LeftPosition+',scrollbars='+scroll+',resizable='+resize+',status' 
    
    window.open(mypage,myname,settings) 
    } 
    
    }
    I don't think this code works 100% but it will give you an idea on how to do it.

    Hope this helps.

  3. #3
    DF VIP Member big man's Avatar
    Join Date
    Jul 2002
    Location
    The big smoke
    Posts
    2,824
    Thanks
    8
    Thanked:        0
    Karma Level
    445

    Default

    Wonderful - Cheers WTD. I'll let you know how I get on.

    Big Man
    I am a loud man with a very large hat. This means I am in charge

    Never argue with an idiot. They will bring you down to their level, then beat you with experience.

  4. #4
    DF VIP Member big man's Avatar
    Join Date
    Jul 2002
    Location
    The big smoke
    Posts
    2,824
    Thanks
    8
    Thanked:        0
    Karma Level
    445

    Default

    Cheers WTD.

    Had a little play around with it and got it working great. Thanks for the help

    Big Man
    I am a loud man with a very large hat. This means I am in charge

    Never argue with an idiot. They will bring you down to their level, then beat you with experience.

  5. #5
    DF VIP Member WTD's Avatar
    Join Date
    Mar 2001
    Location
    Tokyo, Japan
    Posts
    3,256
    Thanks
    0
    Thanked:        0
    Karma Level
    492

    Default

    No worries mate, glad you got it working

Similar Threads

  1. Open Links in Popup window?
    By EUPHORiA in forum Website Coding & Graphics
    Replies: 10
    Last Post: 1st November 2002, 06:12 PM
  2. open membership?
    By psxcity in forum Forum Suggestions & Feedback
    Replies: 11
    Last Post: 13th October 2002, 12:37 AM
  3. Replies: 13
    Last Post: 6th September 2002, 12:48 PM
  4. Thoughts on Open University
    By N3R0 in forum The Dog and Duck
    Replies: 24
    Last Post: 31st August 2002, 01:18 AM

Social Networking 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
  •