Jump to content

Updating parent window


adam84

Recommended Posts

From my parent window I open up a child window. What I want to do is run something in the child window, then onces it competes. Update a div tag in the parent then close the child window.

 

this is my JS in the child window

function update_parent(){
window.opener.document.getElementById('resultDIV').innerHTML = 'Here I am';
}

 

When I test this, I get an access denied JS error. Any ideas on what I should do or change? Thanks

Link to comment
https://forums.phpfreaks.com/topic/214191-updating-parent-window/
Share on other sites

Works fine for me. Must be a problem somewhere else in your code. Here is the code I tested with

 

Parent

<html>
<body>

<button onclick="window.open('child.htm')">Open Child</button>

<div id="resultDIV">Doesn't work</div>

</body>
</html>

 

Child

<html>
<head>

<script type="text/javascript">

function update_parent()
{
  window.opener.document.getElementById('resultDIV').innerHTML = 'works';
  window.close();
}

</script>

</head>
<body>
<button onclick="update_parent()">Update Parent</button>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.