www.webdeveloper.com
Results 1 to 5 of 5

Thread: Window popup code

  1. #1
    Join Date
    Oct 2003
    Posts
    12

    Question Window popup code

    I want to have a standard sized popup window that I can call from anywhere on the page. I'm a bit all thumbs with JavaScript but here is what I've tried. It half works, how can I better clean it up?

    Also...
    The header code is to contain the size, as my try below. Don't know whether to use menubar=0 or menubar=no

    Any ideas greatfully accepted.

    <SCRIPT LANGUAGE="Javascript1.1" TYPE="text/javascript">
    <!--
    function PopWindow(url){

    window.open(url,"win",' toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=1, resizable=1, width=520, height=350');

    }
    //-->
    </SCRIPT>

    <BODY>

    <A HREF = "javascript:PopWindow('target_page.html')">This is a popup link</A>

  2. #2
    Join Date
    Dec 2002
    Location
    Manchester, UK
    Posts
    6,275
    With pop-up's all of the options are by default set to off (unless you don't have a third arguement), so you don't need all of those something=0. This script should do what you want:

    Code:
    <script type="text/javascript"><!--
    
    function PopWindow(url){ 
    
    window.open(url,'win','scrollbars=1, resizable=1, width=520, height=350');
    
    }
    
    //--></script> 
    
    </head>
    
    <body>
    
    <a href="target_page.html" onclick="PopWindow(this.href);return false;">This is a popup link for JavaScript enabled browsers</a>
    Every fight is a food fight when you’re a cannibal.

  3. #3
    Join Date
    Oct 2003
    Posts
    12
    That's just great, I've seen something similar but it was oddly coded, yours is cleaner. Out of interest, is the bit ;return false mean that if something is missing, like the URL, that it returns an error?

  4. #4
    Join Date
    Jul 2003
    Location
    Boston Area, Massachusetts
    Posts
    3,489
    Originally posted by VirtualBob
    Out of interest, is the bit ;return false mean that if something is missing, like the URL, that it returns an error?
    http://forums.webdeveloper.com/showt...r=2#post126008

  5. #5
    Join Date
    Dec 2002
    Location
    Manchester, UK
    Posts
    6,275
    Just a quick translation to clear up any potential mis-understandings.

    First off, the ";" is just a delimeter, it is used to put more than one JavaScript command on a line, I use it at the end of everything so that I will never get an error for missing one off. (A good habit to pick up.)

    When you click a link, the following events occur in this order (as far as JavaScript is concerned):

    onmousedown
    onmouseup
    onclick

    And then when the JavaScript has finished with it, the actual clicking of the link occurs (usually taking the user to a new page).

    If you use "return false" at the end of the onmousedown, onmouseup or onclick handlers it stops the link from doing what it would usually do after that particular event.

    In the script I have set it so that it will open the pop-up for JavaScript enabled browsers, but JavaScript disabled browsers they will ignore the onclick attribute and just treat it as a normal link, that way everyone can see what you want to show them.

    I have not used target="_blank" because that would open a new window and would therefore break the back button which would cause some users considerable confusion.
    Every fight is a food fight when you’re a cannibal.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles