当单击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>
Run Code Online (Sandbox Code Playgroud)
与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>
Run Code Online (Sandbox Code Playgroud)
为什么这样,或者如何onclick在HTA中使用iframe按钮中的事件执行父函数?
使用:
<iframe id="frame" onload="load_me" application="yes"></iframe>
Run Code Online (Sandbox Code Playgroud)
见简介.HTA,部分信任的力量:卫生技术评估和安全