[英]Javascript : add string to iframe with window.opener form popup
我使用此代碼將字符串添加到父 windows 表單彈出窗口的元素:
window.opener.document.getElementById('myid').innerHTML += 'string';
現在我想將字符串添加到彈出窗口 iframe 的元素中。iframe 和父項都在同一個域中。 我嘗試了這段代碼但沒有用:
parent.myframename.window.opener.document.getElementById('iframeelementid').innerHTML += 'string';
怎么了? 有什么辦法嗎?
謝謝你的幫助。
*更新*
這是我的完整代碼。 主頁:
<html>
<head>
<script>
function myPopup() {
window.open( "pop.htm", "myWindow", "status = 1, height = 180px, width = 330px)
}
</script>
</head>
<body>
<textarea id="input"><iframe src="frame.html" name="myframe"></iframe> </textarea>
<a href="" onclick="myPopup()">Popup</a>
</body>
</html>
和 pop.htm:
<html>
<head>
<script>
function insert() {
parent.myframe.window.opener.document.getElementById('inframe').innerHTML += 'asasasas';
window.close();
return false;
}
</script>
</head>
<body>
<input type="button" id="insert" onclick="insert()" value="insert" />
</body>
</html>
和 iframe.html:
<html>
<head>
</head>
<body>
<span id="inframe"></span>
</body>
</html>
使用此代碼:
window.opener.document.getElementById('iframeelementid').innerHTML += 'string';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.