views:

66

answers:

3

I made this PHP chatbox which supports some JavaScript code.

I have these 'images' which if you click them make special codes inside the textfield. e.g:

<head>
    <script language="javascript">
    function addCode(code)
    {
        document.writeform.bericht.value+=code;
        document.writeform.bericht.focus();
    }
</head>
<body>
    <a
      href="#"
      onclick="addCode('<a href="http://www.your-link.com"&gt;Your-Text&lt;/a&gt;');"
    ><img src="img.gif" /></a>
</body>

Which would put the HTML link code into the textfield so the user can edit this easily.

Now I have this popup which needs to do the same thing as before, but because it's in a new window it needs to talk to the other page (chatbox.php).

How can I do it?

+1  A: 

You want to "talk" from the popup to the "opener":

opener.writeform.bericht.value+=code;
Augenfeind
+5  A: 

In your all-in-one-page code, document is a property of the global object (global to the window), which is window (e.g., document === window.document). If code on that page opens a new window, within the new window there's a property called opener you can use to reference the window that opened the new window (opener references the opening window), so:

opener.document.writeform.bericht.value+=code;
T.J. Crowder
Thanks, this helped me.
YourComputerHelpZ
and i would like to close the popup automaticcly when a link is clicked and the function has been done.
YourComputerHelpZ
never mind. just window.close()
YourComputerHelpZ
A: 

Yes, the key being, before you run the popup, to name it, and name it inside the called PHP page, using JavaScript, then they will be able to send data between pages.

crosenblum