CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Sep 2009

    JavaScript focus() does not work on IE

    I have an ASP.NET 2.0 page with a button that opens a popup with FileUpload dialog. The code below is doing that.

    In Chrome and FireFox popup opens and stays in focus, as intended. However, in IE6 and IE7 it opens but then the main window gets in front of it.

    How can I change my JavaScript building code in C# to keep that popup on top in IE7 (our standard browser)?


    /// Javascript Open Popup Window Method
    _sb.AppendLine("function openPopup(url) {");           
    _sb.AppendLine("        popup = window.open(url,'FileUpload','height=200,width=420,resizable=yes');");
    _sb.AppendLine("                if (window.focus) {popup.focus()}");            
    _sb.AppendLine(String.Format("openPopup('{0}');", "FileUpload.aspx"));
    Last edited by PeejAvery; September 10th, 2009 at 07:00 PM. Reason: Added code tags.

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002

    Re: JavaScript focus() does not work on IE

    I would make it so that the popup receives focus regardless of the other windows focus.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Sep 2009

    Re: JavaScript focus() does not work on IE

    here is working solution (in the popup window):

    <body onload="setTimeout('self.focus()', 10)">


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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.