簡體   English   中英

Javascript:使用 window.opener 表單彈出窗口將字符串添加到 iframe

[英]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';

您可以使用window.opener

這里

window.opener.document.getElementById('ID').innerHTML +=  'Yor STR';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM