Jump to content

Recommended Posts

How can i pass value to parent window?

 

Let say

 

page1.php

<input type="button" value="open window" onclick="javascript:window.open('page2.php')">

<div id="test"></div>

 

page2.php

<input type="button" value="close window" onclick="passvalue('HELLO WORLD')">

 

so what should be written in function passvalue() so that the words "HELLO WORLD" shown up in <div id="test"></div>??

 

what i've tried so far in confusion and not working is this

function passvalue(x)

{

window.parent.document.getElementById("test").innerHTML=x;

window.close();

}

 

thx for any help

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/220825-pass-value-to-parent-window/
Share on other sites

The parent window should be referred to as "opener"

  function passvalue(x)
    {
        window.opener.document.getElementById("test").innerHTML=x;
        window.close();
    }

 

Here's a working example using your code: http://www.realtown.com/test5.php

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.