2

单击 iframe 内的按钮时,此 HTML 文件会显示消息对话框:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <script language="VBScript" type="text/vbscript">

      Sub load_me()
        frame.document.write "<input type='button' onclick='parent.message()'>"
      End Sub

      Sub message()
        MsgBox "Hi"
      End Sub

    </script>
  </head>

  <body>
    <iframe id="frame" onload="load_me"></iframe>
  </body>
</html>

虽然与 HTA 文件相同的文档,但会引发错误Error: Object doesn't support this property or method::

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Test</title>
    <HTA:APPLICATION
      APPLICATIONNAME="Test"
      ID="MyHTMLapplication"
      VERSION="1.0"/>

    <script language="VBScript">

      Sub load_me()
        frame.document.write "<input type='button' onclick='parent.message()'>"
      End Sub

      Sub message()
        MsgBox "Hi"
      End Sub

    </script>
  </head>

  <body bgcolor="white">
    <iframe id="frame" onload="load_me"></iframe>
  </body>
</html>

为什么会这样,或者如何使用onclickHTA 中 iframe 按钮的事件执行父函数?

4

1 回答 1

7

利用:

<iframe id="frame" onload="load_me" application="yes"></iframe>

请参阅.HTA 简介信任的力量:HTA 和安全部分

于 2013-02-12T14:45:44.760 回答