473,609 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.someFun ctionInMain(par am1,
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="testPop up()">
<script type="text/javascript">
<!--
var popupWindow;

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

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

// NOTE this doesn't seems to work either
popupWindow.onu nload = 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="blahValu e"/>
</form>
</body>
</html>

Aug 16 '07 #1
3 7361
On 16 Ago, 15:45, Jimmy <jimmy_ple...@y ahoo.comwrote:
It is also possible for popup window to call function in main window
by using the opener property. Will "opener.someFun ctionInMain(par am1,
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="testPop up()">
<script type="text/javascript">
<!--
var popupWindow;

function testPopup() {
popupWindow = window.open("ch ild.html", "Pop", "width=700,
height=400, scrollbars=1, dependent=yes") ;
popupWindow.foc us();

}

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

// NOTE this doesn't seems to work either
popupWindow.onu nload = 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="blahValu e"/>
</form>
</body>
</html>
I post the right code:
<html><head></head><body onLoad="testPop up()">
<script type="text/javascript">
<!--
var popupWindow;

function testPopup()
{
popupWindow = window.open("ch ild.html", "Pop", "width=700,
height=400, scrollbars=1, dependent=yes") ;
popupWindow.foc us();

// put here.....anonym ous works on MOZILLA!!!!
popupWindow.onu nload = function()
{
alert("closing child");
}

}
-->
</script>
<body onload="testPop up()">
</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="testPop up()">
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("ch ild.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.foc us();
`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.....anonym ous works on MOZILLA!!!!
Your Exlamation Mark key is borken.
popupWindow.onu nload = function()
{
alert("closing child");
}
This *may* work.
}
-->
This line is unecessary and error-prone; `-', `--' and `>' are operators.
</script>
<body onload="testPop up()">
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.de mon.co.uk>
Aug 16 '07 #3
On Aug 16, 3:24 pm, Thomas 'PointedEars' Lahn wrote:
josh wrote:
>function testPopup()
{
popupWindow = window.open("ch ild.html", "Pop", "width=700,
height=400, scrollbars=1, dependent=yes") ;
<snip>
// put here.....anonym ous works on MOZILLA!!!!

Your Exlamation Mark key is borken.
> popupWindow.onu nload = 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
3397
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 to Javascript to execute the new window opening. But as it does this, the main window is loaded which is blank (the browser URL bar shows the URL of the URL passed to the PHP / Javascript script). I would like to keep the gallery page visible...
3
1758
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
2485
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 statusbar. Yet FF gives me both a statusbar and the window is resizable! Does this mean that FF does not support these "features" or is there a different way to code them for FF?
5
2853
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 the result to main page (I mean, update the parent page). My popup form looks like this: <form name="form1" action="run.php" method="get" target="???">
5
2505
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 database the DataGrid is using as a data source. When the popup window is closed I want to refresh the main window -- i.e., cause a postback to happen. Is this possible?
1
5402
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 that), the popup window will have also a text box and a button. when the User click on the button the value on the textbox will be send back to the textbox on My_WUC. I hope I was clear off what I want to do. I've been searching for some ideas...
8
2479
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" type="text/javascript"> <!-- ; var newwindow = ''
2
2744
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 break that connection from the parent side or the child side, it doesn't matter as long as the communication link is completely broken. I don't want the parent to be aware of the child and vice-versa.
1
17592
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" width=18 height=20 border=0> </a> In this showWindow function.... var newWindow = '';
0
8571
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8220
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8404
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6997
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6056
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4080
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1386
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.