473,785 Members | 2,221 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how can i close a pop up from the parent onload

when a form is submitted from the main window i want a pop up window
to open from the onclick event. i have that working, now how can i
close the pop up window from the main window after the main window
finishes loading? i've been racking my brain on this for the last two
days. here is the code for the parent window that i have been testing
with.

testfoo.htm is just a blank html page used for testing.

<head>
<title>Personne l Information</title>
<script language="javas cript" type="text/javascript">
var newWindow;
//alert(newWindow + " page load");

function openDialogWin() {
var height = "300";
var width = "500";
var x = (screen.width - width) / 2;
var y = (screen.height - height) / 2;
var Name = window.name;
//alert(height + ", " + width);

features = "height=" + height + ",width=" + width + ",left="
+ x + ",top=" + y;
features += ",menubar=no,re sizable=no,titl ebar=no,scrollb ars=no,status=n o,toolbar=no,me nubar=no,locati on=no";
var newWindow = window.open(une scape("/testfoo.htm"),
"newWindow" , features);
//alert(newWindow .name + " in openDialogWin") ;
return newWindow;
}

function closeDialogWin( ) {
if (newWindow && !newWindow.clos ed)
newWindow.close ();
}
</script>

</head>
<body onLoad="closeDi alogWin();">
<form method="post">
<input type="submit" name="foo" value="Submit"
onclick="openDi alogWin();">
</form>
</body>
</html>

sorry about the formatting... it looks ok in the editing window. if
anyone can clue me in on how to format the code for the boards, i'll
do my best to comply.

thanks in advance

jones
Jul 20 '05 #1
11 2959
In article <94************ **************@ posting.google. com>,
ja********@hotm ail.com enlightened us with...
when a form is submitted from the main window i want a pop up window
to open from the onclick event. i have that working, now how can i
close the pop up window from the main window after the main window
finishes loading? i've been racking my brain on this for the last two
days. here is the code for the parent window that i have been testing
with.

You redeclared newWindow, so what you did was create a local var and the
global is unchanged.
features += ",menubar=no,re sizable=no,titl ebar=no,scrollb ars=no,status=n o,toolbar=no,me nubar=no,locati on=no";
var newWindow = window.open(une scape("/testfoo.htm"),
"newWindow" , features);


Take away that "var".
newWindow = ...

You don't need to return newWindow from that function either, since
nothing caught it anyway.

--
--
~kaeli~
Not one shred of evidence supports the notion that life is
serious.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #2
i removed the "var", but now i am getting an "Error: 'newWindow' is
undefined". also, i am passing 'newWindow' back and forth between the
parent and child windows.

jones

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
i removed the "var", but i'm still running into the same problem -
newWindow is undefined and is not being close by the closeDialogWin
function.

jones

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4
In article <40************ ***********@new s.frii.net>,
ja********@hotm ail.com enlightened us with...
i removed the "var", but i'm still running into the same problem -
newWindow is undefined and is not being close by the closeDialogWin
function.


It's hard to close a window that hasn't been opened.
You're calling the close before the open (close called from onLoad).

There was a syntax error, too.

This worked fine in IE6.
Note: url and form attributes changed for testing.
Watch for word-wrap.

<html>
<head>
<title>Personne l Information</title>
<script language="javas cript" type="text/javascript">
var newWindow=null;

function openDialogWin()
{
var height = "300";
var width = "500";
var x = (screen.width - width) / 2;
var y = (screen.height - height) / 2;
var Name = window.name;

features = "height=" + height + ",width=" + width + ",left="+ x
+ ",top=" + y;
features +=
",menubar=no,re sizable=no,titl ebar=no,scrollb ars=no,status=n o,toolbar=no
,menubar=no,loc ation=no";
newWindow = window.open("te st.html","newWi ndow", features);
//alert(newWindow .name + " in openDialogWin") ;
return;
}

function closeDialogWin( )
{
if (newWindow && !newWindow.clos ed)
newWindow.close ();
}
</script>

</head>
<body>
<form>
<input type="button" name="foo" value="Open"
onclick="openDi alogWin();">
<input type="button" name="foo2" value="Close"
onclick="closeD ialogWin();">

</form>
</body>
</html>

--
--
~kaeli~
You feel stuck with your debt if you can't budge it.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #5
using another button to close the window would defeat the purpose of the
script i'm trying to write.

here's a bit more detail about the specific problem i'm having and why i
need this script: users are submitting a form and end up clicking the
submit button multiple times or click on another submit out of
frustration or impatience. i tried disabling all of the buttons on the
page, spent 3 days on that, and decided to go with a "modal" pop up that
would close after the parent page finished processing.

is there another way i should be doing this that would make it clear to
the user that they can not do anything within the application until the
page has finished processing?

oh yeah, was this the corrected syntax:
"var newWindow=null; "

jones

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #6
In article <40************ ***********@new s.frii.net>,
ja********@hotm ail.com enlightened us with...
using another button to close the window would defeat the purpose of the
script i'm trying to write.

Really?
*ahem*

It's for illustrative purposes.
The point is, it works. Making the var global was just fine.
You can close a popup from the opener. Where you put that statement is
up to you, but trying to put it before the popup loads will result in an
error.

here's a bit more detail about the specific problem i'm having and why i
need this script: users are submitting a form and end up clicking the
submit button multiple times or click on another submit out of
frustration or impatience. i tried disabling all of the buttons on the
page, spent 3 days on that, and decided to go with a "modal" pop up that
would close after the parent page finished processing.

Is there some flaw in your application that having a user click on
submit more than once makes it crash?
Or is it just that the page then submits again and the user waits
longer, so you want a popup?
If the former, fix it.
If the latter, this isn't going to do you any good, since submitting a
page clears out the old page and references to the popup window are
lost.
Now, if the form is posted to a NEW window, thus keeping the old window
and code, you can close the popup when the form is done processing with
a little convoluted code in the window that the form posted to. But I
have a feeling that isn't what you're going for.

If your users are on the slow side, like mine, and have only recent DOM
browsers with javascript enabled, like mine, you can put the submit in a
wrapper, make a variable (init to false) that is set to true when the
submit button is clicked, then any time the button is clicked, checks
that variable to be false before submitting.
Note that this is not at all a good solution for general internet use.
Very, very bad for general use. Works like a charm for intranet apps and
other situations where you know your users and their browsers.

oh yeah, was this the corrected syntax:
"var newWindow=null; "


No. Sorry, my bad - the syntax error was my fault when I took out that
unescape and didn't remove both parens.

--
--
~kaeli~
Who is General Failure and why is he reading my hard disk?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #7
as you can probably guess, i only dabble in javascript and primarily on
an as-needed basis. this - submitting a page clears out the old page
and references to the popup window are lost - is probably one of the
most usefull bits of information that i have picked up over the last
several days and helps make sense out of a lot of other things.

i think i'll give this wrapper you mentioned a try and see how that
turns out.

-off topic: are you using a news reader or accessing this group from a
website? if you're using a website, could you let me know what it is?
i'm not to thrilled with using developersdex to access them.

thanks for the help

jones

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #8
In article <40************ ***********@new s.frii.net>,
ja********@hotm ail.com enlightened us with...
as you can probably guess, i only dabble in javascript and primarily on
an as-needed basis. this - submitting a page clears out the old page
and references to the popup window are lost - is probably one of the
most usefull bits of information that i have picked up over the last
several days and helps make sense out of a lot of other things.

Oh, you're welcome.
Sometimes the cause of a problem is totally nowhere you thought it was.
i think i'll give this wrapper you mentioned a try and see how that
turns out.

Since you're a newbie, do you know what I meant by that?
If you need me to clarify, let me know.

I'll start you with

var subbed = false;
function mySubmit(frm)
{
if (!subbed)
{
subbed = true;
frm.submit();
}
else
{
alert("Please be patient.");
}
}

<form action="whateve r.asp" method="post" onSubmit="retur n false;">
<input type="button" onClick="mySubm it(this.form)">

Note that the onSubmit handler is NOT called when using javascript
form.submit(), something I am taking advantage of here to prevent going
around the wrapper by using the default behavior of hitting the enter
key when focus in ona text element. However, this makes the form
unusable by non-javascript-enabled browsers, so caveat emptor.
-off topic: are you using a news reader or accessing this group from a
website?


Gravity Newsreader.
Sorry.

However, I hear there are free newsservers out there. You may want to
post an OT asking about it and recommendations .

--
--
~kaeli~
When you choke a smurf, what color does it turn?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #9
here is my final solution - and surprisingly it works! thanks to
everyone who viewed and replied to this thread.

well, i couldn't find any better solution and since i've been wracking
my brain over this since last wednesday, i took the easy way out and am
faking disabling the button. i put the original submit buttons inside of
a span with an id of "able" and created identical dummy buttons inside
of a span called "disabled". when one of the original buttons is
clicked, it hides "able" and displays "disabled". and since this is done
on the client side, the change is instant in their browser (as far as i
know). here is the code i used:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled </title>
<script language="JavaS cript">
function bigFake() {
able.style.disp lay = "none";
disabled.style. display = "";
}
</script>
</head>

<body>

<form name="formA" action="#formac tion#" method="post">
<span id="able">
<input type=submit name="btnSave" value="Save (Does Not Forward)"
onclick="bigFak e();"><br><br>
<input type=submit name="btnBack" value=" <- Back "
onclick="bigFak e();">&nbsp;&nb sp;&nbsp;
<input type=submit name="btnReturn " value="Return"
onclick="bigFak e();">&nbsp;&nb sp;&nbsp;
<input type=submit name="btnForwar d" value="Forward"
onclick="bigFak e();"><br><br>
</span>

<span id="disabled" style="display: none">
<input type=submit name="btn1" value="Save (Does Not Forward)"
disabled><br><b r>
<input type=submit name="btn2" value=" <- Back "
disabled>&nbsp; &nbsp;&nbsp;
<input type=submit name="btn3" value="Return"
disabled>&nbsp; &nbsp;&nbsp;
<input type=submit name="btn4" value="Forward" disabled><br><b r>
</span>
</form>

</body>
</html>
jones

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #10

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

Similar topics

3
5185
by: J P Singh | last post by:
Hi Guys Wonder if someone can help me with this. I have a form where a user clicks a button which gives them a pop up windows to allow them to add the data. The user adds the data and click save. The pop window closes and refreshs the parent window to allow the entered data to be displayed. It was all working okay until couple of days back when it stopped.
1
3764
by: Marshall Dudley | last post by:
I have an application where in a shopping cart checkout a popup appears which suggests other items that may go with what was ordered with a button to add these items to the cart. When the button in the popup is clicked, the popup should present an added items to cart message, close, and reload the parent window, so the parent will show the new item in the cart. It is all working except the post contents for the parent window are being...
1
3373
by: gopal srinivasan | last post by:
I need to know how to close a parent modal window when child modal window opens, also i need to know the syntax for writing document on the modal window on the fly, like what we do in case of normal window. Actually, I tried to close the parent window from the child modal window using parent.close syntax in onload event in child modal window. It actually closes the parent modal window, but the child modal window is not opened, why it is...
4
5668
by: Colin Graham | last post by:
Hi guys, Just a quickie here that i hope someone can help me with. Basically i want stop the user from closing the popup window using the small x button in the top right hand corner. Im aware that i cant disable this so i thought is it possible to do a check to see if a hidden text on the main form has a value. E.g. if we close the popup correctly then text box on the main form will say true. If we close the text box using the x in the...
1
1833
by: Marcel | last post by:
I have a subwindow hich displays a grid. When the user selects a row from the grid, I wish to store the selected row ID in session state and close the subwindow, returning focus to the parent (opener). Normally I would do this in javascript, but I cannot find any client side intelligence in the grid, so I wish to close the window on the select index changed event when I return to the server. I can't remeber how to add an OnLoad...
4
14475
by: stevong | last post by:
It works on Konquerer though. I remember it works on IE too. I've tried window.close() too. Doesn't work on Firefox also. I've also tried to create a function. It doesnt work on Firefox also. Bottomline is: Firefox doesn't accept window.close() or self.close()? Are there ways to rectify the issue? Please advise.
7
2513
by: Jaggu | last post by:
Hi , I need to close main window, once the child window succesfully opens else main window to remain. In my case when I close the main window immediately after the "window.open()" as mentioned below, both the main and child disappears(this is due to pop up blocker) disappears suddenly. I want to make the browser know if pop up blocks the child window(in case). help me how to check the child window opened successfuly or not, on
1
2473
by: Socrates | last post by:
Hi - Have tried for half and hour to get this script to work: I am trying to close the parent window while opening a centred new child window I would be grateful if someone could correct the script below which does open a new window, but not in a centred position. Here is the link to the url:
13
5518
by: petcancervet | last post by:
I am writing a PHP/MySQL web-page based system on Firefox and wish to run a separate page from an <Alink to run a separate PHP script, then close that page. Firefox starts a new tab for this and it closes OK but I am then left with an egg-timer at the mouse arrow when over top or bottom toolbars areas of the parent page. I am using <BODY onLoad='Javascript:close()'to fire the tab closure. I have tried opener.focus() with no effect. I...
0
9489
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10162
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
10100
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
9959
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
8988
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...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2893
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.