我已經看到了這個的一些示例帖子,但我似乎有點難倒爲什麼他們都沒有工作。從iFrame訪問標籤到其父母
這裏是什麼,我想實現一個堆棧視圖:
<html>
<head>...</head>
<body>
<div>Some stuff, images, text</div>
<div><audio id="audio"><source> src="me.mp3" /></audio></div>
<div>Some stuff, images, text</div>
<div>
<iframe src="file.html">
#document
<html>
<head>...</head>
<body>
<div><button id="stopPlay">Stop Play</button></div>
</body>
</html>
</iframe>
</div>
<div>Some stuff, images, text</div>
</body>
</html>
有人建議,要訪問音頻標籤,你會使用類似:
window.parent.document.getElementById('audio');
其中給出即使這兩個文件都在同一臺服務器上,我也是一個原始錯誤。所以我再次建議document.domain = "[email protected]"
,並將其放在iframe和parent中。但仍然給我一個與DOM相關的錯誤。
當我正在尋找堆棧,然後搜索它以查找元素時,如何在其他建議爲其他人工作時執行此操作?
在我的最後工作得很好,這是你的確切代碼嗎?我從字面上複製粘貼到兩個文件,我能夠操縱iframe內的音頻標籤。我用localhost作爲域。 – Patrick
這是我得到的錯誤:> [錯誤]阻止了一個起源爲「null」的框架訪問一個起源爲「null」的框架。協議,域和端口必須匹配。 \t Playparent中的錯誤:TypeError:undefined不是一個對象(評估'window.parent.document.getElementById') –
如果我添加'document.domain =「[email protected]」'我得到這個錯誤在playparent :錯誤:SecurityError:DOM異常18 –