Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

return value from popup window 1

Status
Not open for further replies.

stormbind

Technical User
Joined
Mar 6, 2003
Messages
1,165
Location
GB
Can you get a value back from a popup window in the same way as a prompt() or modal dialog thingy?

Thanks for your thoughts on this matter :D

----------
I'm willing to trade custom scripts for... [see profile]
 
You mean specifically when the user closes the popup, or at any time?

If on close, what would you want the value to be? True if they've closed it, false otherwise (although how could it ever be false? ;o)...

If it's not on close, then you could just use window.opener to call a function in the opening window, passing any values as parameters.

Hope this helps,

Dan
 
I plan to have it return a value on close :)

The popup window contains images. There's only one thing to do and that's select an image to be pasted into the form in the main document.

This works great with modalwatchimowidget in MSIE but I would like to emulate the effect in NN4/Mozilla aswell.

----------
I'm willing to trade custom scripts for... [see profile]
 
Mozilla has a method for modal / modeless dialogs...it's something like openDialog() (google for it)

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Thanks, but I wish this to work in all browsers not just IE/Moz. Is there no way to use a regular window?

----------
I'm willing to trade custom scripts for... [see profile]
 
using a regular window, you can have a script attached to window.onunload to send your value back.

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
This works for me:

Main code:
Code:
<html>
<head>
<script language=&quot;javascript&quot;>
<!--
	function openWin() { var winHandle = window.open('popupCode.html', '', ''); }
//-->
</script>

</head>
<body>
	Click <a href=&quot;javascript:openWin();&quot;>here</a> to open a new window.
	<br><br>
	The last window you closed returned a value of: <span id=&quot;returnValue&quot;> </span>
</body>
</html>

popupCode.html:
Code:
<html>
<head>
<script language=&quot;javascript&quot;>
<!--
	function sendValueToOpener()
	{
		window.opener.document.getElementById('returnValue').innerHTML = document.getElementById('valueField').value;
	}
//-->
</script>
</head>
<body onunload=&quot;sendValueToOpener();&quot;>
	<form>
		Type in a value to get returned when this window closes: <input type=&quot;text&quot; id=&quot;valueField&quot;>
	</form>
	<br><br>
	Click <a href=&quot;javascript:window.close();&quot;>here</a> to close the window.
</body>
</html>

Hope this helps,

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top