第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

是否可以訪問(wèn) iframe 外部的數(shù)組?

是否可以訪問(wèn) iframe 外部的數(shù)組?

天涯盡頭無(wú)女友 2023-10-17 19:54:30
問(wèn)題是這樣的:在我的主頁(yè) ( parent.html) 中,我有一個(gè) iframe ( child.html) 和一個(gè)腳本塊。在該腳本塊中,有一個(gè)整數(shù)數(shù)組和一個(gè)將元素添加到列表中的函數(shù)。在 iframe 中,有一個(gè)新函數(shù)可以將元素添加到主文件 ( parent.html) 的列表中。我想知道 iframe() 是否可以child.html訪問(wèn)parent.html. 例子:父級(jí).html<html>    <head>        <title>Parent</title>        <script>            var parentList = [0];            var counter = 0;            function addValue(){                counter++;                parentList.push(counter);                console.log('parent', parentList);            }        </script>    </head>    <body>        <button onclick="addValue()">Add Value (Parent)</button>        <br />        <iframe src="child.html" allowfullscreen></iframe>    </body></html>孩子.html<html>    <head>        <title>Child</title>    </head>    <body>        <button onclick="addValueInternal()">Add Value Child</button>        <script>            var internalCount = 0;            function addValueInternal() {                internalCount++;                parentList.push(internalCount);                console.log('child', parentList);            }        </script>    </body></html>錯(cuò)誤:child.html:12 Uncaught ReferenceError: parentList is not defined    at addValueInternal (child.html:12)    at HTMLButtonElement.onclick (child.html:6)
查看完整描述

1 回答

?
蠱毒傳說(shuō)

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超3個(gè)贊

是的。有可能的。

因此,在您的情況下,您必須parent在訪問(wèn)數(shù)組時(shí)引用 。

function addValueInternal() {

? internalCount++;

? parent.parentList.push(internalCount); // here we access the reference

? console.log('child', parentList);

}

請(qǐng)注意,之后您可能會(huì)遇到有關(guān)跨域策略的問(wèn)題。


查看完整回答
反對(duì) 回復(fù) 2023-10-17
  • 1 回答
  • 0 關(guān)注
  • 141 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)