472,988 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,988 software developers and data experts.

Main window call Javascript function in popup window, and vice versa

It is also possible for popup window to call function in main window
by using the opener property. Will "opener.someFunctionInMain(param1,
param2)" in the popup window work?

It's possible for main window to call function in the popup window,
right? The following is a sample code (close popup window causes to
show alert window) which doesn't seems to work. Can anyone see the
problem?

// main
window /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

<html><head></head><body onLoad="testPopup()">
<script type="text/javascript">
<!--
var popupWindow;

function testPopup() {
popupWindow = window.open("child.html", "Pop", "width=700,
height=400, scrollbars=1, dependent=yes");
popupWindow.focus();
}

// NOTE this one doesn't work in Mozilla and just commented out
//popupWindow.onunload = function() {
// alert("closing child");
//}

// NOTE this doesn't seems to work either
popupWindow.onunload = doOnunload;
function doOnunload() {
// expecting alert window will show up when popup window close
alert("closing child");
}
-->
</script>
</body></html>

// popup
window /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

<html><head></head>
<body>
<form id="blahForm">
<input type="hidden" id="blahId" value="blahValue"/>
</form>
</body>
</html>

Aug 16 '07 #1
3 7319
On 16 Ago, 15:45, Jimmy <jimmy_ple...@yahoo.comwrote:
It is also possible for popup window to call function in main window
by using the opener property. Will "opener.someFunctionInMain(param1,
param2)" in the popup window work?

It's possible for main window to call function in the popup window,
right? The following is a sample code (close popup window causes to
show alert window) which doesn't seems to work. Can anyone see the
problem?

// main
window /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

<html><head></head><body onLoad="testPopup()">
<script type="text/javascript">
<!--
var popupWindow;

function testPopup() {
popupWindow = window.open("child.html", "Pop", "width=700,
height=400, scrollbars=1, dependent=yes");
popupWindow.focus();

}

// NOTE this one doesn't work in Mozilla and just commented out
//popupWindow.onunload = function() {
// alert("closing child");
//}

// NOTE this doesn't seems to work either
popupWindow.onunload = doOnunload;
function doOnunload() {
// expecting alert window will show up when popup window close
alert("closing child");}

-->
</script>
</body></html>

// popup
window /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

<html><head></head>
<body>
<form id="blahForm">
<input type="hidden" id="blahId" value="blahValue"/>
</form>
</body>
</html>
I post the right code:
<html><head></head><body onLoad="testPopup()">
<script type="text/javascript">
<!--
var popupWindow;

function testPopup()
{
popupWindow = window.open("child.html", "Pop", "width=700,
height=400, scrollbars=1, dependent=yes");
popupWindow.focus();

// put here.....anonymous works on MOZILLA!!!!
popupWindow.onunload = function()
{
alert("closing child");
}

}
-->
</script>
<body onload="testPopup()">
</body>
</html>

Bye

Aug 16 '07 #2
josh wrote:
I post the right code:
What is supposed to be "right" about this code is beyond me.
<html><head></head><body onLoad="testPopup()">
http://validator.w3.org/
<script type="text/javascript">
<!--
It is unnecessary, and it is error-prone to try to "comment out" script
element content. Worst case: syntax error.
var popupWindow;

function testPopup()
{
popupWindow = window.open("child.html", "Pop", "width=700,
height=400, scrollbars=1, dependent=yes");
window.open() is a host object's method that should be feature-tested before
being called.

"Pop" maybe is used already as window name, so the respective window will be
reused. This can be prevented if a timestamp, being a unique number over
time, is prefixed, infixed or suffixed to the window name.

The feature string must not contain spaces. It has to be `scrollbars'
(without `=1') to be compatible. `dependent' (without `=yes') suffices.
IMHO, a popup should always be `resizable' as well; scrollbars sometimes
fail to do their job.
popupWindow.focus();
`popupWindow' may not return a Window object reference, so it should be
subject to a type-converting test. Window::focus() is a host object's
method that should be feature-tested for.

It may not even work because current browsers have an option to prevent
windows from being focused by scripting. (IIRC, it was discussed recently
here.)
// put here.....anonymous works on MOZILLA!!!!
Your Exlamation Mark key is borken.
popupWindow.onunload = function()
{
alert("closing child");
}
This *may* work.
}
-->
This line is unecessary and error-prone; `-', `--' and `>' are operators.
</script>
<body onload="testPopup()">
This unrequested popup will probably not open because of a popup blocker.
Furthermore, there is a duplicate `body' element, or a `script' element
outside the `body' element (whatever way you want it), which is not Valid
markup (see above.)
</body>
</html>
Please *don't reply* if you lack the minimum clue. Nobody is helped
by that (except maybe yourself). Thank you for your attention.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Aug 16 '07 #3
On Aug 16, 3:24 pm, Thomas 'PointedEars' Lahn wrote:
josh wrote:
>function testPopup()
{
popupWindow = window.open("child.html", "Pop", "width=700,
height=400, scrollbars=1, dependent=yes");
<snip>
// put here.....anonymous works on MOZILLA!!!!

Your Exlamation Mark key is borken.
> popupWindow.onunload = function()
{
alert("closing child");
}

This *may* work.
<snip>

It seems unlikely that it would. There will be a timing issue where
the new browser window is opened and makes its HTTP request to the
server, the script goes on to execute the above and attach an onunload
handler to the window object of the new browser window, and then the
HTTP response arrives, loads a new page, and clears all of the
listeners previously associated with the window, along with all the
other script assigned properties of the window object.

Aug 16 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dariusz | last post by:
I have a problem with a call a Javascript "window.open()" function which is executed as part of a PHP file when a user clicks on an thumbnail image. The PHP is executed which passes some variables...
3
by: Chris | last post by:
Hi, I'm really begginer in javascript. I created a form in a pop-up opened with javascript. how to recover variables of the form in the main page. Thanks for your help Chris.
18
by: Andrew Poulos | last post by:
If I manage to call the following bit of javascript in IE and MZ w = window.open("", "s", 'status=no,resizable=no,width=450,height=450'); I get a window that is not resizable and without a...
5
by: Hemanth | last post by:
Hello there, I'm running a script that opens a popup window (which is basically a form with checkboxes and a submit button). When I click the submit button I want to run a PHP script and target...
5
by: Jay | last post by:
I have a situation where the user clicks on a button in a DataGrid to launch a popup window via javascript. In the popup window the user does some things that result in changes to the underlying...
1
by: Jorge Ponte | last post by:
hi I have a Web User Control (ascx) - lets call it "My_WUC" - in a Web form. In that WUC I want have a textbox and a button. I want to click on the button and open a popup (I use javascript for...
8
by: johnsonholding | last post by:
Here is the code for a pop-up window that works in Firefox and not in IE - I get a java error or something, Here is the code : </script> <SCRIPT language="JavaScript"...
2
by: epaetz | last post by:
Is there a way to decouple the linkage between a parent and a child window? Does the parent window have any sort of a collection that holds all the children that it has spawned? I want to...
1
by: pingalkar | last post by:
Hi, In my application, I call one popup winodow by using this link.. <a href="#" onClick="return showWindow('1','XYZ');"> <img src="images/magnifier.gif" ALT="Chemicals"...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.