IE7 problem when using popups

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alejandro
    New Member
    • Mar 2007
    • 27

    IE7 problem when using popups

    Hey everyone, I'm currently working on a php project that started about 3 years ago (meaning, it's already quite large.).

    It uses quite a lot of pupups that seem to work great in all browsers... or used to until IE 7 came along.

    The problem is, if I have a link that generates a popup but also relocates the page where the link was clicked, the main page will come on top of the popup when it starts loading (this does not occur in any other browser other than IE 7.). This occurs if the page has an onload event that sets focus somewhere in the page.

    I will provide an over-simplified example, try it out in FF, IE 6, and IE 7 to see what I mean:

    content of popup.html:
    <html>
    <head>
    <script language='javas cript'>
    window.onload = function (){ window.document .getElementById ('inputThing'). focus(); };
    </script>
    </head>
    <body>
    <a href='popup.htm l' onclick="window .open('popup.ht ml','','width=2 00,height=200') ;">Click Me</a>
    <input id='inputThing' type='text'></input>
    </body>
    </html>
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN - The Scripts.

    Set focus to the popup window.

    Comment

    • alejandro
      New Member
      • Mar 2007
      • 27

      #3
      thanks for the welcome.
      I already tried that, but it will not work: the main window will give the focus to the popup, however, afterwards it will start loading the page in the href and come on top of the popup.

      Comment

      • alejandro
        New Member
        • Mar 2007
        • 27

        #4
        Code:
        <html>
          <head>
            <script language='javascript'>
        	  window.onload = function (){ window.document.getElementById('inputThing').focus(); };
              function popup(){
                var newWindow = window.open('popup.html','','width=200,height=200');
                newWindow.focus(); // This will execute, but afterwards the window that executes
                                   // it will reload and come on top of the popup window
              }
            </script>
          </head>
          <body>
            <a href='popup.html' onclick="popup();">Click Me</a>
            <input id='inputThing' type='text'></input>
          </body>
        </html>
        Just trying out the [ code][ /code] thingy :D

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          If you want to avoid a reload of the page, put "return false;" after window.open.

          Comment

          • alejandro
            New Member
            • Mar 2007
            • 27

            #6
            that's part of the problem, I don't want to avoid the reload. It's part of the specs, the popup should open and the window should relocate to a different location :S
            Also, I don't think a return false would work, since the link has a href :P

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Originally posted by alejandro
              that's part of the problem, I don't want to avoid the reload. It's part of the specs, the popup should open and the window should relocate to a different location :S
              Also, I don't think a return false would work, since the link has a href :P
              A return false would work. It prevents the browser following the link.

              Anyway, to work around your problem, call setTimeout to cause a delay. Then set focus to the popup.

              Comment

              • alejandro
                New Member
                • Mar 2007
                • 27

                #8
                acoder, thank you very much for all your help, I hate to be a pain.

                The problem is, no matter what javascript I write in the main window, it will relocate to the href after executing it (so, even if I cause a delay and give focus to the popup, the main window will relocate after executing this code and come on top of the popup, only in IE7, of course).

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  Well, one possibility is to give focus onload to the popup by passing a parameter to to the page, e.g. popup.html?win= popid where popid is the ref. to the popup. Use the location.search property (link). I don't know if it will work, haven't tried it. Then use that to set focus to the popup after giving focus to the input element.

                  Another possibility is to let the popup perform the reloading by:
                  Code:
                  window.opener.window.location.reload()
                  These are only suggestions. See if they work.

                  Comment

                  • iam_clint
                    Recognized Expert Top Contributor
                    • Jul 2006
                    • 1207

                    #10
                    Code:
                    <html>
                      <head>
                    	<script language='javascript'>
                       window.onload = function (){ window.document.getElementById('inputThing').focus  (); };
                    	  function popup(){
                    		var newWindow = window.open('popup.html','','width=200,height=200'  );
                    		window.setTimeout("newWindow.focus()", 2000); // This will execute, but afterwards the window that executes
                    						   // it will reload and come on top of the popup window
                    	  }
                    	</script>
                      </head>
                      <body>
                    	<a href='popup.html' onclick="popup();">Click Me</a>
                    	<input id='inputThing' type='text'></input>
                      </body>
                    </html>
                    try this

                    Comment

                    • alejandro
                      New Member
                      • Mar 2007
                      • 27

                      #11
                      thanks clint.

                      didn't work, the main window reloads after executing the javascript code (after giving the focus to the popup), and that's when it comes on top of the popup.

                      dang IE 7.

                      Comment

                      • iam_clint
                        Recognized Expert Top Contributor
                        • Jul 2006
                        • 1207

                        #12
                        SCREW IE7!!!!

                        lol I have had so many bugs with ie 7.


                        Instead of a link transferring you accross pages make a javascript do it

                        window.location

                        then do your window and focus


                        give this a try.

                        Comment

                        • alejandro
                          New Member
                          • Mar 2007
                          • 27

                          #13
                          Love to do that, the problem is I'm working on an already functional system with over 300 template html files (no clue on how many links in there have this problem, but quite a few) :P

                          I think I'm gonna keep track of recently opened popups myself, and give focus to whatever popup was recently opened in the main page's onload.

                          It's odd that no one has posted anything regarding this issue in the past tho, I usually find tons of info when I encounter a browser-related bug :P

                          Comment

                          • alejandro
                            New Member
                            • Mar 2007
                            • 27

                            #14
                            Coded it, looks terrible, the popup loses focus for a fraction of a second before regaining it.

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              #15
                              See this page. Search for "focus". Maybe they didn't fix it...

                              Comment

                              Working...