how can i close a pop up from the parent onload

J

JSjones

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=no,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
 
K

kaeli

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=no,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
 
K

Kevin Jones

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
 
K

Kevin Jones

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
 
K

kaeli

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=no,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>

--
 
K

Kevin Jones

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
 
K

kaeli

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.

--
 
K

Kevin Jones

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
 
K

kaeli

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.

--
 
K

Kevin Jones

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
 
R

Randy Webb

Kevin said:
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....
 
K

kaeli

<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".

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top