mkohan Posted September 11, 2008 Share Posted September 11, 2008 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 Quote Link to comment Share on other sites More sharing options...
lemmin Posted September 11, 2008 Share Posted September 11, 2008 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. Quote Link to comment Share on other sites More sharing options...
mkohan Posted September 11, 2008 Author Share Posted September 11, 2008 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 Quote Link to comment Share on other sites More sharing options...
lemmin Posted September 11, 2008 Share Posted September 11, 2008 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); } Quote Link to comment Share on other sites More sharing options...
mkohan Posted September 12, 2008 Author Share Posted September 12, 2008 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§ion=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 Quote Link to comment Share on other sites More sharing options...
lemmin Posted September 12, 2008 Share Posted September 12, 2008 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§ion=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. Quote Link to comment Share on other sites More sharing options...
mkohan Posted September 12, 2008 Author Share Posted September 12, 2008 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.