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.
Page 1 of 3 123 LastLast
Results 1 to 15 of 34
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation How to I set focus to a new window?

    Hi,

    I am trying to create a popup window to open a custom page and keep focus until the user forces it to close by clicking a close link. I created the following function and then I call it:

    function topWindow()
    {
    popup = window.open('test.htm','Testing','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollb ars=no,resizable=no,width=400,height=200,left=350,top=200'); return false;
    }

    I call it in an IF statement within another function:

    if (count<1)
    topWindow();


    My custom page has the following in the body tag:

    <body onload="windows.focus()" onBlur="self.focus()">

    When I test this, sometimes it stays on focus, but other times, it is moved behind the main page, which I don't want. I want it to popup over the main page and the close it in order to continue navigating.

    Any suggestions? I was thinking of an if statement that if it doesn't have focus, put focus back on it, but I'm not sure of the syntax for that and if it is possible. Thanks!
    Last edited by limshady411; 08-19-2005 at 11:27 PM. Reason: reworded to a question
    limshady411

  • #2
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Remove all the other code in the body tag, and loops, etc and just have this to make sure the popup appears in front when it loads:
    Code:
    function topWindow() {
      var popup = window.open('test.htm','Testing','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollb ars=no,resizable=no,width=400,height=200,left=350,top=200');
      popup.focus();
    }
    There is a way to always keep the popup in front of the window that opened it but users shouldn't be forced into this functionailty - it's a bad idea to impede the users, and that would really irritate users - I know it would annoy me!

    JavaScript should be used to enhance, not impede the interactivity of the page. Don't forget that users can simply switch off JavaScript or not revisit the site again if they feel the scripts are not doing them any favours.

    Hope this helps.

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #3
    New Coder
    Join Date
    Aug 2005
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your response. Well, originally, I had code for an alert to do this (which required the user to click ok), but that was causing another issue. So I was trying to come up with a similar alternative for my alert, which would be a new window with the same message and similar closing option as the alert. I know it's annoying, but I'm only making the code per a request of the project. It's on the Intranet and that's what the project team is aiming at. What do you think? Thanks.
    limshady411

  • #4
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If it is an intranet and all the browsers will be IE, there is a special type of popup that has just those properties:
    Quote Originally Posted by MSDN Library

    Modeless dialog box. The modeless dialog box allows a user to interact with the original window while the dialog box is open. In this situation, the dialog box remains on top of the browser in a disabled state. If the user navigates away from the original document, the modeless dialog box is automatically dismissed, as all context for the dialog box is lost. An advanced-find functionality might well use such a dialog box to enable the user to select found text in the document while keeping the dialog box open so that he or she can quickly proceed to the next instance of the found text.
    Modal dialog box. The modal dialog box allows the program to focus the user's full attention on a particular dialog box and to require interaction with it before continuing. An example of that might be a data-entry operation in which certain data must be entered before the application can continue.
    From this link.

  • #5
    New Coder
    Join Date
    Aug 2005
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your response. It's kind of tricky. We have kiosks that we will be setting up that will not be using Internet Explorer, but another browser similar to Firefox. The alert works just fine in Firefox without any issue, except in IE, we have the issue. I'm trying to get either an alert to work on both without issue, or a new popup window with the same message as the alert to work on both. So far, I'm thinking the new window, remaining on focus until the user closes it with a close button, can be the better solution, if I can get it to stay on focus...what do you think? Thanks again!
    limshady411

  • #6
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why isn't the alert any good in IE? Alert works nearly identically in IE and FF. In any case, you can keep focus on a popup window until it is closed (at least within the confines of the page that opened it) using this method:
    Code:
    function popUp(URL) {
    var page = window.open(URL, 'page2', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=300,left = 192,top = 144');
    page.focus()
    document.onclick=function(){
    try{
    page.focus();return false
    }catch(e){}
    }
    }
    Another approach would be to use the appropriate modeless or modal dialogue for IE and the alert for FF.

  • #7
    New Coder
    Join Date
    Aug 2005
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your response. The alert works fine in IE and FF, however, in IE, it's causing links in my navigation frame to highlight other links (complicated unless you see it). Anywho, the code you gave me does exactly what I need in IE, but in FF, it's not working. If I lose focus, it goes behind my main window, which I don't want, and in the case of the Kiosk, it stays in the background permanently. any other ideas?? Thanks though, if we went with IE for the Kiosk, we would be set right now...
    limshady411

  • #8
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In FF there is a configuration option that will allow it to work as in IE.

    Tools - Options - Web Features - javascript - advanced

    Make sure "Raise or lower windows" is checked. Since you have control over the browsers used in your Kiosks (I would assume), you can probably set this for one copy of the browser and then clone it to all other copies in some way.

  • #9
    New Coder
    Join Date
    Aug 2005
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your response. I check the settings and it was already enabled So with or without that option, it doesn't keep the focus...any other thoughts? Thanks again!
    limshady411

  • #10
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Odd, worked here. The really promising suggestion I made that you seem to have overlooked is to use one method for IE and another for FF. Generally IE can be selected:
    Code:
    if (document.all){
    code for IE goes here
    }
    else {
    code for FF goes here
    }
    It is more complicated than that in the 'real world' but, if you are only using the two browsers, that is sufficient.

  • #11
    New Coder
    Join Date
    Aug 2005
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks. This does exactly what I needed it to do. The kiosk software that I'm using seems not to be Mozilla Firefox because it doesn't do the alert (the else statement if the browser was anything other than IE), but instead, it does a pop up window, which should be IE. I think this kiosk browser is utilizing some component of IE. It's very strange. Thanks for all your help!
    limshady411

  • #12
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The only other browser aside from IE that utilizes document.all that I know of is Opera. It can be selected out using:
    Code:
    if (document.all&&!window.opera){
    code for IE goes here
    }
    else {
    code for Mozilla & Opera goes here
    }

  • #13
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Firefox also has modal dialogs by specifying modal=1 in the window feature.
    Code:
    var win;
    if (window.showModalDialog) { //IE
      win = window.showModalDialog("test.htm" , "", "dialogWidth:500px; dialogHeight:500px;");
    }
    else{
      win = window.open("test.htm", "modalWin", "modal=1, width=500, height=500");
    }

  • #14
    New Coder
    Join Date
    Aug 2005
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your responses. The browser that I'm using seems to integrate IE...it's odd. It's from a company called Arlington (http://www.arlington.com.au/akb/moreinfo.htm). It's odd...
    limshady411

  • #15
    New Coder
    Join Date
    Aug 2005
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I was thinking of another solution...that if my popup does lose focus (which when it does on the kiosk puts its in the background), I can do a timeout to close that window. I just don't know the if statement to do so:

    if: <not window.focus()>
    timer = setTimeout("window.close()",1000);

    What do you think?

    Thanks.
    limshady411


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

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