Jump to content

Passing values from popup window to the parent window


mkohan

Recommended Posts

Hi,

 

I have a popup window which have many records link (values)dynamically created.

 

By clicking on the links value on the popup window (child) the JavaScript should pass the value  and creates a link on the parent window.

 

Is it possible to pass value from child window one by one to the parent window and based on each click the parent window creats a link?

 

Thanks,

 

 

MK

 

Link to comment
Share on other sites

Yeah, you can do that. Here is an example of how:

 

This would be the code for the window you are opening (or you could just use write()):

<html>
<head>
<script type="text/javascript">
function addLink(obj)
{
newLink = self.opener.document.createElement("a");
newLink.href = obj.id;
newLink.innerHTML = obj.innerHTML;

self.opener.document.getElementById("dLinks").appendChild(newLink);
}
</script>
</head>

<body>
<a id="http://www.google.com" href="javascript://" onclick="addLink(this);">Link 1</a>
<a id="http://www.yahoo.com" href="javascript://" onclick="addLink(this);">Link 2</a>
</body>
</html>

 

And this would be the code for the page that opens it:

<html>
<head>
<script type="text/javascript">
function doPopup() 
{
newWin = self.open("phone.htm");

}
</script>
</head>

<body>
<button onclick="doPopup();">Open Popup</button>
<div id="dLinks"></div>
</body>
</html>

 

I took the word "link" in your question literally but you should be able to modify this code to add whatever you want.

Link to comment
Share on other sites

Excellnet. Thanks lemmin.

I used  a  link  <a href="#" onClick="window.open('child1.htm','Ratting','width=500,height=400,left=250,top=200,toolbar=0,status=0,');">Open Popup</a>

I tested it worked fine.

 

I have another problem too in my real application the parent window has a <textArea></textArea> when clicking on the link on the child window, that link should go inside of textArea.

 

Is it possible to implement this example to it?

Thanks for your help.

 

MK

 

 

Link to comment
Share on other sites

It actually should work with a textarea instead of a div, but you wouldn't actually be able to click on the link inside of the textarea. If you just want the actual URL of the link in the textarea then you can just add text like this:

function addLink(obj)
{
newLink = self.opener.document.createTextNode(obj.id + "\n");
self.opener.document.getElementById("dLinks").appendChild(newLink);
}

Link to comment
Share on other sites

Thanks  lemmin,

I tried on textarea  <textarea id="dLinks"></textarea>  it worked.

 

 

But acutly I want to  pass smothing like this to the parent window.

 

<a href='#'

onClick="window.open('find.php?file=12&section=test','Ratting','width=500,height=400,left=250,top=200,toolbar=0,status=0,');>

 

 

I tried to put it on id      <a id=" " onclick="addLink(this);">Link 1</a>   

it did not worK.

it is possible to do that.

Thanks,

MK

Link to comment
Share on other sites

Yeah, you can do that. I was just using the id for simplicity, but you can do something like this:

function addLink(obj, link)
{
newLink = self.opener.document.createElement("a");
newLink.href = link;
newLink.innerHTML = obj.innerHTML;

self.opener.document.getElementById("dLinks").appendChild(newLink);
}

<a href="javascript://" onclick="addLink(this, 'onclick="window.open(\'find.php?file=12&section=test\',\'Ratting\',\'width=500,height=400,left=250,top=200,toolbar=0,status=0,\');"');">Link 1</a>

 

The quoting gets all weird doing it this way but I don't know exactly what you are trying to do so I can't guess at a better method. Also, like I said, you probably won't actually be able to follow the link from inside the textarea.

Link to comment
Share on other sites

Thanks lemmin,

 

That works with IE but does not work with Firefox.

 

Also the <textarea> is inside of the Form  and users after adding the links to the textarea  use submit button to save the content of the text area.

 

I just wondering if the textarea content will be saved.

 

Thanks for your help.

MK

 

 

Link to comment
Share on other sites

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.