![](/img/trans.png)
[英]npm run build doesn't work.“Opening index.html over file:// won't work.”
[英]Getting HTML Parent Window Won't Work. Suggestions?
我有以下兩個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>
<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內部我想更改父文檔中的變量ExamID(即:Main.html)。 我正在嘗試通過JavaScript函數執行此操作:setParentInfo()。
上面的代碼不起作用。 有人可以幫我提出正確的代碼嗎?
非常感謝!
變量在window
對象上分配,而不是document
對象。
由於該值已設置,您可以改為讀取現有值以進行驗證:
alert(window.parent.ExamId); // == "001A"
在父窗口中聲明和分配變量,以便從子窗口獲取引用。
你可以使用alert
語句測試:
alert(window.parent.document.ExamId);
//output::001B
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.