简体   繁体   中英

Need an alternative to using window.resizeTo function

I believe a bug fix to Firefox is causing me grief when using the window.resize function in my asp pages. I am desperately seeking an alternative to this and would be most grateful for any suggestions...

My pages are currently setup the following way

I have a main page , lets call it main.asp. Within main.asp I have a html form with a button. The button, when clicked called a javascript function to open a new window like to:

<html>
    <head>
        <title>Main Page</title>
    </head>
    <body>
        <SCRIPT LANGUAGE="javascript">
        function popupNew()
        {
            var win = window.open('child.asp', '_blank', 'width=400,height=260,directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes');
            win.focus();
        }
        </SCRIPT>
        <table>
            <tr>
                <td>
                    <button type="button" style="width:50px; font-family:arial,sans-serif; font-size:11px;" onclick="popupNew();">Add</button>
                </td>
            </tr>
        </table>
    </body>
</html>

Ok so as you can see I can open child.asp from main.asp. Within Child asp, I have a form. The form stores a boolean on whether or not valid data has been posted. I use this boolean to determine the size of the window (if the data is not valid, I resize the window to allow for an error message. Here is a rough example of how this goes down...

<html>
  <head>
    <title>Child Page</title>
  </head>
  <body onload="_onLoad()">
    <SCRIPT LANGUAGE="javascript">
    function _onLoad()
    {
      var sResizeForError = String(document.getElementById("ResizeForError").value);

      if(sResizeForError == "true")
      {             
        window.resizeTo(400, 520);
      }
    }
    </SCRIPT>
    <form name="PageForm" method="Post" action="">
      <input type="hidden" name="ResizeForError" id="ResizeForError" value="true"/>
    </form>
  </body>
</html>

For some unknown reason, the window no longer resizes in firefox, it works fine however in IE

Thoughts? Are there better ways of doing this other than window resize?

As you've found bug information it's true that Firefox 7 locked down window resizing if it wasn't opened with window.open or window contains more than one tab.

You can fond more information on this on the internet:

What can you do?

Since opening new windows has lots of security and usability issues and it may as well be locked down in the future as well (although unlikely) it's best for you to either:

  • open your form centrally positioned (horizontally and vertically) in your main window
  • if your main window content should stay there and user focus should switch to the form, you can open the form in a modal HTML window that many libraries support (like jQuery UI )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM