469,290 Members | 2,009 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,290 developers. It's quick & easy.

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>Personnel Information</title>
<script language="javascript" 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,resizable=no,titlebar=no,scrollbars=n o,status=no,toolbar=no,menubar=no,location=no";
var newWindow = window.open(unescape("/testfoo.htm"),
"newWindow", features);
//alert(newWindow.name + " in openDialogWin");
return newWindow;
}

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

</head>
<body onLoad="closeDialogWin();">
<form method="post">
<input type="submit" name="foo" value="Submit"
onclick="openDialogWin();">
</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 2763
In article <94**************************@posting.google.com >,
ja********@hotmail.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,resizable=no,titlebar=no,scrollbars=n o,status=no,toolbar=no,menubar=no,location=no";
var newWindow = window.open(unescape("/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***********************@news.frii.net>,
ja********@hotmail.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>Personnel Information</title>
<script language="javascript" 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,resizable=no,titlebar=no,scrollbars=n o,status=no,toolbar=no
,menubar=no,location=no";
newWindow = window.open("test.html","newWindow", features);
//alert(newWindow.name + " in openDialogWin");
return;
}

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

</head>
<body>
<form>
<input type="button" name="foo" value="Open"
onclick="openDialogWin();">
<input type="button" name="foo2" value="Close"
onclick="closeDialogWin();">

</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***********************@news.frii.net>,
ja********@hotmail.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***********************@news.frii.net>,
ja********@hotmail.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="whatever.asp" method="post" onSubmit="return false;">
<input type="button" onClick="mySubmit(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="JavaScript">
function bigFake() {
able.style.display = "none";
disabled.style.display = "";
}
</script>
</head>

<body>

<form name="formA" action="#formaction#" method="post">
<span id="able">
<input type=submit name="btnSave" value="Save (Does Not Forward)"
onclick="bigFake();"><br><br>
<input type=submit name="btnBack" value=" <- Back "
onclick="bigFake();">&nbsp;&nbsp;&nbsp;
<input type=submit name="btnReturn" value="Return"
onclick="bigFake();">&nbsp;&nbsp;&nbsp;
<input type=submit name="btnForward" value="Forward"
onclick="bigFake();"><br><br>
</span>

<span id="disabled" style="display: none">
<input type=submit name="btn1" value="Save (Does Not Forward)"
disabled><br><br>
<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><br>
</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
Kevin Jones wrote:
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="JavaScript">
function bigFake() {
able.style.display = "none";
disabled.style.display = "";
}
</script>

you should test that in something besides IE....

--
Randy

Jul 20 '05 #11
In article <40***********************@news.frii.net>,
ja********@hotmail.com enlightened us with...

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


This will fail in NN/Moz.
You forgot document.getElementById("able") syntax is required in non-IE
browsers. Only IE knows that shortcut you used.
NN says "able is not defined".

--
--
~kaeli~
A man's home is his castle..., in a manor of speaking.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Marshall Dudley | last post: by
4 posts views Thread by Colin Graham | last post: by
1 post views Thread by Marcel | last post: by
1 post views Thread by Socrates | last post: by
13 posts views Thread by petcancervet | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.