次の 2 つの HTML ドキュメントがあります。
Main.html
<html lang="eng">
<head>
<title>JavaScript Example</title>
<script type="text/javascript">
var ExamId = "001A";
function open_exam()
{
window.open("exam.html")
}
</script>
</head>
<body>
<input type=button value="Open Exam" onclick="open_exam()">
</body>
</html>
Exam.html
<html lang="eng">
<head>
<title>JavaScript Example</title>
<script type="text/javascript">
function setParentInfo()
{
window.parent.document.ExamID = '001B';
}
</script>
</head>
<body>
<p>Welcome to the Exam!</p>
<input type=button value="Set Parent Info" onclick="setParentInfo()">
</body>
</html>
Main.html は、入力ボタンを介して Exam.html を呼び出します。Exam.html 内から、親ドキュメント (つまり、Main.html) の変数 ExamID を変更したいと思います。JavaScript 関数 setParentInfo() を使用してこれを実行しようとしています。
上記のコードは機能しません。誰かが正しいコードを思いつくのを手伝ってくれますか?
本当にありがとう!