SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    window.onblur hinders to type into fields

    I have
    Code:
    window.onblur = function()
    {
        this.focus();
    }
    Problem is that this is also triggered when I click on a textfield, so basically, this makes it impossible to write in the text fields... Doh. Is there any way I can avoid this?

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should be able to use var e.target or e.srcElement to determine if the focused element is a textfield

  3. #3
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tried that already, IE returns null when i click on the text field.

  4. #4
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How about the reverse - If e.target == window, do the focus, else bail out. I assume that you want to simulate a modal window by re-acquiring focus, when the user tries to leave the window ?

  5. #5
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Exactly, simulating a modal dialog window, since you can't do posts to a showModalDialog window (IE only intranet, but I also make sure it works in other browsers, so I prefer to simulate this).

    if e.target == window will also not work, since it will always return null.

  6. #6
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Only crap solution I can think of is to have a boolean flag telling what element has the focus. So basically set this flag to true if an a field have the focus. This means that I need to attach onblur and onfocus events to all fields though. So yeah, crap solution.

  7. #7
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had a look at my own modal-dialog script, and what I do there, is that I set a onfocus-handler on the opening window, rather than setting a onblur-handler on the "modal" window. Just remember to remove it when the modal closes.

  8. #8
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually I have both... Since just having it on the the modal window is not bulletproof.

    Nor is it bulletproof to only set the focus from the main window (just click on it a couple of times and the focus on the modal window is lost)


  9. #9
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I fixed most of thoose problems by making an invisible div, which covers the whole screen of the opener window. It makes it impossible to press a button/link directly in the opener-window. You can still force yourself into trouble by visciously clicking on the opener document, but the invisible div will make the opener document unresponsive.

  10. #10
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, but you can still close the main window.

    I seem to have found a solid solution I am looking into now. They are using setCapture, onlosecapture events to make this work in IE. Will write back here once I figure it out how they did it.

  11. #11
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sounds interesting - I'd like to see what you find out.

    Wouldn't it be acceptable to put a handler for onunload in the opener window, which closes the modal too ?

  12. #12
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I guess so. Good point. Stuff I found so far is really interesting (IE only), basically the modal window would react to events, not the main window. No need to cover the main window with a div etc.

    Will get back to this thread when I have a working example.

  13. #13
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    You don't need to look at creating an IE only solution since IE already has a modal dialog facility built in. What is needed is a way to do it on all browsers except IE and I haven't found anything that works to do this anywhere.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  14. #14
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    felgall, IE:s modal dialog can't help me in this case, since you can't do a POST to a dialog, therefore the fake.

    Reason we do a POST to the dialgo is that we are using JSF (Javaserver Faces).


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
  •