Self.opener and innerHTML

Gary
Gary used Ask the Experts™
on
Is it possible from a popup window to set innerHTML in a div or span on the parent window, tried a few ways but couldnt get it to work

Basically got a drop down that fires the popup onchange, the popup does some processing and I want to put the result on the parent window, formatted etc
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
hi GaryC123,

yes it possible, with syntax:  opener.document.all.myDiv.innerHTML="your text or html"

where in parent window you have <div id=myDiv></div>




here another example with function:


==============FILE parent.html============================
<script>
function nw()
{
     openChild = window.open("child.html","","left=300,width=200");

}
function post_from_child(ps)
{
    document.all.myDiv.innerHTML+=ps+"<br>"
}
</script>

<button onclick=nw()>Open Child </button><br>
<button id=myDiv></button>







==============FILE child.html============================
<form>
Just click on inputs and look to parent window<br>
<input value="hello world!" onclick=opener.post_from_child(this.value)><br>
<input value="hello world!" onclick=opener.post_from_child(this.value)><br>
<input value="hello world!" onclick=opener.post_from_child(this.value)><br>
<input value="hello world!" onclick=opener.post_from_child(this.value)><br>
<input value="hello world!" onclick=opener.post_from_child(this.value)><br>
</form>
Saqib KhanSenior Developer
Commented:
> document.all.myDiv.innerHTML+=ps+"<br>"

is only IE 5.5 +

to make it work for IE 5.5+ and Netscape 6+

use

document.getElementById("myDiv").innerHTML="<p>Hello World"
Michel PlungjanIT Expert
Top Expert 2009
Commented:
actually document.all is ie4+ but getElementById should be used as Adil suggests :)
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Commented:
or even better:
var obj = document.getElementById?document.getElementById('myDivID'):document.all?document.all.myDivID:null;
if (obj) obj.innerHTML='...';

Commented:
Er, with the appropriate opener. before document, above.
I like the way of doing a making a function with
opener.function(var)
although that only works if the parent window has a function in it.
need a simple way of doing it so it will work from for any parent window so the opened doc can modify the parent.
:-)
I like the way of doing a making a function with
opener.function(var)
although that only works if the parent window has a function in it.
need a simple way of doing it so it will work from for any parent window so the opened doc can modify the parent.
:-)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial