当点击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>
为什么会这样,或者如何在HTA中使用iframe按钮的onclick
事件执行父函数?
答案 0 :(得分:7)