0

网站是这样的:

    `--main.html
    `--dialog.html
    `--folder
        `--iframe.html

代码在这里:
main.html:

    <html>
    <head>
    <script type="text/javascript">
        function testframe() {
            var doc = document.getElementById("frame").contentWindow;
            doc.show();
        }
    </script>
    </head>
    <body>
        <iframe src="folder/iframe.html" id="frame"></iframe>
        <br/>
        <button onclick="testframe()">test</button>
    </body>
    </html>

对话框.html:

    <html>
    <head>
    </head>
    <body>
    This is modal dialog!
    </body>
    </html>

iframe.html:

    <html>
    <head>
    <script type="text/javascript">
        function show() {
            showModalDialog('../dialog.html');
        }
    </script>
    </head>
    <body>
        this is ifram
        <br />
        <button onclick="show()">show dialog</button>
    </body>
    </html>

当我单击 iframe 中的显示对话框按钮时,它会正确显示模态对话框。
当我单击 iram 外部的测试按钮时,它会错误地显示模态对话框。

当我单击 iram 外部的测试按钮以在 dilog 中显示正确的页面时,如何解决此问题?

4

1 回答 1

0
iframeDomElement.contentWindow.setTimeout(function() {
   iframeDomElement.contentWindow.childFunc();
}, 0);

此 hack 将使相对路径相对于子窗口。适用于 Firefox 和 chrome,但不适用于 safari。

于 2012-06-05T23:58:56.573 回答