SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Focusing Issues

  1. #1
    SitePoint Zealot Atirez's Avatar
    Join Date
    Nov 2000
    Location
    England
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Focusing Issues

    Hi all,
    I have been having a really odd problem. I have been using the YUI library to open dialogue boxes in a web application, however the cursor has remained on the page behind the dialogue.

    I have tried to move focus to a rich text box in the child page and have succeeded with the following code in IE7, however I can not get the same code to work in firefox.

    Code:
                         var iframe = document.getElementsByTagName("iframe")[0];
                        if(iframe.contentWindow.document.body.createTextRange) {
                            var range = iframe.contentWindow.document.body.createTextRange();
                            range.moveStart("CHARACTER", 0);
                            range.select();
                        }
    I have had to do this as trying to set focus to normal controls in the child window does not seem to work at all.

    Could please someone tell me the equivelant code that would work in firefox please.

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does iframe.focus() not work? Also, what controls do you have in said dialog box?

    Surely YUI should have thought of something like this?!


  3. #3
    SitePoint Zealot Atirez's Avatar
    Join Date
    Nov 2000
    Location
    England
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gRoberts View Post
    Does iframe.focus() not work? Also, what controls do you have in said dialog box?

    Surely YUI should have thought of something like this?!
    Nope, nor does trying to set focus to any input html control either. The only controls we have in the dialogue are a couple of check boxes and a RTE (namely http://www.openwebware.com/ 's openWYSIWYG 1.0).

  4. #4
    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)
    A cheap solution would be to un-focus (blur) the main page. Or to focus any form element in the dialog using the focus method.

    Reason that the code above does not work in Firefox is due to that ranges are implemented differently. Firefox has implemented the DOM range following the W3C standards.


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
  •