单击 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>
为什么会这样,或者如何使用onclick
HTA 中 iframe 按钮的事件执行父函数?