Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Focus on pop up window not working

    function MyPopUpWin(message) {
    var iMyWidth;
    var iMyHeight;
    //half the screen width minus half the new window width (plus 5 pixel borders).
    iMyWidth = (window.screen.width/2) - (75 + 10);
    //half the screen height minus half the new window height (plus title and status bars).
    iMyHeight = (window.screen.height/2) - (100 + 50);
    //Open the window.
    var generator = window.open();
    generator.focus();
    document.onmousedown = focusPopup;
    document.onkeyup = focusPopup;
    document.onmousemove = focusPopup;

    generator.document.write('<html><head><title>Pop uP</title>');
    generator.document.write('<p style="color:#C52B27;">');
    generator.document.write(message);
    generator.document.write('</p>');
    generator.document.write('</head><body>');

    generator.document.write('<a href="javascript:self.close()"><img src="/img/save_orange.gif" border=0"> <\/a>');
    generator.document.write('</body></html>');
    generator.document.close();
    }
    function focusPopup(){
    if(generator && !generator.closed)
    {
    generator.focus();
    }

    }

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,592
    Thanks
    0
    Thanked 644 Times in 634 Posts
    You have two separate functions there,

    The first creates the popup and uses a local variable called 'generator' to load all the content into the popup.

    The second function tests if a global variable called 'generator' exists and if it isn't closed in order to give that the focus. Since no such global variable exists it doesn't give anything the focus.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Tags for this Thread

    Posting Permissions

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