开发者

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>
                <t开发者_JAVA技巧d>
                    <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 I.E.

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's New in Firefox 7 for Developers, No More Window Resize, Improved WebSockets
  • Bug 565541 - Web sites shouldn't be allowed to resize main window - rules that disable resizeTo

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜