【问题标题】:Internet Explorer 9 ignores dialogWidth/Height for showModalDialog with a framesetInternet Explorer 9 忽略带有框架集的 showModalDialog 的 dialogWidth/Height
【发布时间】:2012-01-30 17:01:42
【问题描述】:

我有一个较旧的 Intranet 应用程序,它需要在模式对话框窗口中显示两个框架(一个固定菜单栏和一个可变内容数据视图)。目前,使用window.showModalDialog 函数打开对话框,一切正常,只要我在 Internet Explorer 8(任何视图模式)或 Internet Explorer 9 中打开页面 Compatibility View em> 已启用。

不幸的是,在 IE9 中关闭 兼容性视图 时,无论指定的 dialogWidth 和 dialogHeight 值如何,对话框窗口总是以 266 x 138 像素的大小打开。我创建了一个显示问题的小示例:

index.html(最初加载的页面):

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
    <input type="button" value="popup" 
        onclick="showModalDialog ('dialog.html', null, 'dialogWidth:500px;dialogHeight:400px;resizable:yes')" />
</body>
</html>

dialog.html(在对话框窗口中打开的页面):

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html>
<frameset rows="*, 70">
    <frame src="frame1.html" />
    <frame src="frame2.html" />
</frameset>
</html>

frame1.html/frame2.html(两个框架的内容):

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
    <p>Frame Content</p>
</body>
</html>

仅当我在对话框中显示框架集文档时才会出现此问题。打开常规 html 文档(包含带有一些内容的正文)时,将按照函数调用中指定的方式设置大小。

此外,在加载文档后更改对话框大小仅适用于常规文档,不适用于框架集,例如在 dialog.html 中的开始 html 标记之后插入以下代码:

<head>
    <script type="text/javascript" />
        window.setTimeout (function () { window.dialogWidth = "500px"; window.dialogHeight = "400px"; }, 10000);
    </script>
</head>

由于我不想更改应用程序的整体结构(尤其是基于帧的),而且我不知道我是否做错了什么,或者我是否在 Internet Explorer 中发现了错误,所以欢迎提供解决此问题的提示。

【问题讨论】:

    标签: internet-explorer size modal-dialog frameset


    【解决方案1】:

    我也遇到了同样的问题,最后通过将元标记兼容性更改为 ie8 对我有用。

    删除模型对话框中的所有文档类型,然后添加元标记,如

    "&nlt; meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8 &ngt;"

    我希望这会有所帮助。

    【讨论】:

    • 这个问题最近出现在IE11上。我的对话框没有文档类型,所以我无法使用 D.Calliess 的解决方案。您的解决方案适用于 IE11!
    【解决方案2】:

    我还在Internet Explorer Web Development Forum 上讨论了这个问题,并得到了我想在这里分享的解决方案:

    根据 Microsoft Connect,测试能够验证此问题是否存在 在 Windows 8 Developer 上的 Internet Explorer 10 中已解决

    对于 IE9,可以通过删除 dialog.html 中的 doctype 声明来绕过该问题。这会强制此特定页面进入 Quirks 模式,但随后对话框会再次以正确的大小显示。

    【讨论】:

      【解决方案3】:

      将此代码添加到 dialog.html

      <head>
          <script>
          (function () {
              var _b = document.createElement('body');
              var _doc = document.documentElement;
              _doc.insertBefore(_b, _doc.firstChild );
              _doc.removeChild(_b);
          })();
          </script>
      </head>
      

      【讨论】:

        猜你喜欢
        • 2018-06-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-30
        • 2014-04-25
        相关资源
        最近更新 更多