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 5 of 5

Thread: Window.Focus()

  1. #1
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Window.Focus()

    Hey guys,

    I'm not sure if this is doable. I pop a window, and I want that window to maintain focus until the user closes it. I can keep the window in focus, but the problem is that it contains a form, and if the user starts filling out the form the window thinks it has lost focus, and tries to refocus itself.

    This is bad because my drop downs clear out while a user is making a selection.

    I've search a great deal, but can not seem to find a way to detect the status of a window's focus. It would be great if I could say:

    if (window.isNotFocused) {
    window.focus();
    }

    But no such property exists. How, or is there a way to do what I'm trying to do? Thanks.

  • #2
    Regular Coder
    Join Date
    Dec 2003
    Posts
    132
    Thanks
    0
    Thanked 0 Times in 0 Posts
    2 things come to mind, Im assuming this is javascript...

    1, you can constantly update the window every second:
    Code:
    blah=setInterval("window.focus();",1000);
    or 2(I think this should work), wait for it to blur:

    Code:
    window.onblur="window.focus();";
    Try it with and without the quotes... if 2 doesnt work, then use 1.

    hope that helps
    UNDER CONSTRUCTION

  • #3
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Problem is that if you have a form in that window with lets say some drop downs, the page will "refresh" causing a users drop down to select itself if currently picked. Both methods you provided do this, when picking a form element it essentially "blurs" the window.

  • #4
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i dont know it this will work. or if this is even the correct syntax... but heres my guess....

    if(!window.focus() | !this.form.e.focus()){
    do some code
    }

  • #5
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts

    this should work!

    ok where you are going wrong i think is trying to detect the windows focus!
    instead set an id to the body tag like so:
    <body id=body>

    and then detect the body's focus!

    I'd do it by setting an onblur detect in the body tag:

    <body id=body onblur="ReFocus()">

    as far as script, when the page loads set the focus to the body
    because it doesnt start focused. once it has focus when ever it loses focus it'll focus on the window then focus on the body again.
    hopefully by the body having focus all objects within it count as part of it!

    put the following at the bottom of your source code.
    reason is it'll cause an error if you try to set focus to the body before it is loaded, so you have to focus on it after it has loaded.

    <script javascript>
    document.getElementById('body').focus();
    function ReFocus(){
    window.focus();
    document.getElementById('body').focus();
    }
    </script>


  •  

    Posting Permissions

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