SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2003
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Newbie Window.Open Function Problems

    Hey,
    I'm redesigning my webpage and thought it would be a good idea to have windows popup if someone had a question about terminology. So basically, I wrote a small function that was supposed to popup a 400x300 window centered towards the top left of the screen with some basic parameters...
    this code is inserted into the head
    Code:
     
    <Script Language="JavaScript 1.1" type="text/javascript;version=1.1">
     function jargon(url){
      var screenw = 800;
      var screenh = 600;
      screenw = screen.width;
      screenh = screen.height;
      var mywin = window.open(url, 'jargon', 'left=screenw / 4,   top=screenh / 4, width=400, height=300, toolbar=0, menubar=0, resizeable=0, status=0');
    }
    </script>
    (the screenw and screenh are meant for older browsers)
    which is meant to be embedded in the code like....
    Code:
     
    <a href="#" onclick="jargon('../jargon/php.php');">PHP</a>
    But whenever I try this, it just uses the # link and nothing happens. Any ideas?

  2. #2
    SitePoint Wizard Bill Posters's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <script type="text/javascript" language="Javascript1.1">
    
    function jargon(url) {
      var winX = window.screen.availWidth / 4 ;
      var winY = window.screen.availHeight /4 ;
    	
      var mywin = window.open(url,'jargon','top='+winX+',left='+winY+',width=400,height=300,toolbar=0,menubar=0,resizeable=0,status=0');
    }
    
    </script>
    Look at the differences between your code and this and you'll get an idea of where it was going wrong.

    Is there any reason that you're referencing 800x600 screens specifically in the code?
    Fwiw, there's no point in specifying it in your code as the var is rewritten in the lines that follow those var declarations.
    New Plastic Arts: Visual Communication | DesignateOnline

    Mate went to NY and all he got me was this lousy signature

  3. #3
    Team SitePoint AlexW's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne
    Posts
    832
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    There a really neat little article at accessify.com on putting the perfect popup together.

    http://www.accessify.com/tutorials/t...ect-pop-up.asp

    Check it out.
    Alex Walker
    SitePoint Developer
    SitePoint - Learnable

  4. #4
    SitePoint Member
    Join Date
    Jan 2003
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Bill Posters
    Code:
     
    <script type="text/javascript" language="Javascript1.1"> 
     
    function jargon(url) { 
    var winX = window.screen.availWidth / 4 ; 
    var winY = window.screen.availHeight /4 ; 
     
    var mywin = window.open(url,'jargon','top='+winX+',left='+winY+',width=400,height=300,toolbar=0,menubar=0,resizeable=0,status=0'); 
    } 
     
    </script>
    Look at the differences between your code and this and you'll get an idea of where it was going wrong.

    Is there any reason that you're referencing 800x600 screens specifically in the code?
    Fwiw, there's no point in specifying it in your code as the var is rewritten in the lines that follow those var declarations.
    Go figure that javascript string syntax is more complicated than java or php (imo). But I added some of that and it works pretty well, and the article was very useful as well. Thanks guys!


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
  •