This HTML file shows message dialog when button inside iframe is clicked:
<!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>
While same document as HTA file, raises error: 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>
Why is that, or how can I execute parent function with onclick
event from iframe button in HTA?
Use:
<iframe id="frame" onload="load_me" application="yes"></iframe>
See Intro to .HTA, section The Power of Trust: HTAs and Security
来源:https://stackoverflow.com/questions/14834888/iframe-event-executes-fine-in-html-but-not-in-hta