Click to See Complete Forum and Search --> : A few questions...


dmason165
04-08-2003, 02:52 PM
Hi all,

I actually have a few questions.

1) Is it possible to have setTimeout() call a function? If so, how? I've tried using this:

<body onLoad="setTimeout(PostWelcome(), 10000);>

Obviously this isn't working. The function is called without regard to time (it's called immediately instead of the desired setTimeout).

2) I am trying to make a link do this:
Confirm:
if OK, the page will open a new window and close itself;
if CANCEL, the page will return to the page from which
the confirmation came (the welcome page).
While reverting users to a page which gives instructions on
how to enable JavaScript (sort-of a detection of whether or
not the user has JavaScript enabled).

My scripts look like this:

<head>
<script language="JavaScript" type="text/JavaScript">
<!--
function PostWelcome(theURL,winName,features) {
var agree=confirm("Confirm your decision.\nClick OK to open the homepage to this site.\nClick CANCEL to exit.");
if (agree) {
window.open("/Home/1/%7E.htm",'','toolbar=no,resizable=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no');
self.close
}
}
-->
</script>
</head>
<body>
<p class=MsoNormal align=center style='text-align:center'><span
style='font-size:150.0pt;font-family:"Palace Script MT"'><a href="/EnablingJavaScript,Cookies&ActiveXControls/%7E.htm"
onClick="PostWelcome(); return false;">Welcome</a></span></p>
</body>

Now what happens is, the second window opens but the
original window doesn't close itself.

Jona
04-08-2003, 02:55 PM
Okay, on your confirm script it needs to be self.close(); not self.close. It's not ASP. :P

As for the setTimout question, you have to do this:

<script>
function foo(){ alert("foo!!"); }

window.setTimeout("foo()", 1000);
</script>

Instead of your onLoad event which calls the function immediatly. Note that this will execute the function every second, so every second you'll be alerted: "foo!!"

dmason165
04-08-2003, 02:58 PM
Thanks Jona!

I guess maybe I should have known that...lol. Thank a million Jona!

~dmason165

Jona
04-08-2003, 03:02 PM
Hey, it was easy enough. As long as it's not hard I don't mind... LOL. I'm just kiddin', I love a challenge. :P

dmason165
04-08-2003, 03:15 PM
How would I make it so the page being opened only does so if the user selects YES when asked if they would like to close the current window? If they select NO, the page to be opened doesn't open.

I've tried using:

<body onUnload="PostWelcome();">

However, now that I've added other links to this page, if a user follows another link, the function PostWelcome() is being called. I only want the function PostWelcome() called when the user follows one particular link (the same link which detects if JavaScript is enabled).

Thanks!

~dmason165

Jona
04-08-2003, 03:19 PM
Dude, you lost me! You mean if they confirm YES it opens a new window and closes the current window, but if they choose NO it will do nothing?

var config = /*Your window specs*/
if(confirm("Do you want to open a new window and close this one?")){ window.open("file.html","fileName",config); }
else {//do nothing
}
}

dmason165
04-08-2003, 03:33 PM
The function PostWelcome() opens a new window and closes the current window (the Welcome page). Because the Welcome page is not open by JavaScript, IE will ask users if they want to close the window when it tries to close itself.

So, when this happens, is there anyway to delay the opening of the new window until this selection is made? It can probably only be done using something like onUnload but I'm not anywhere near competent in this subject:) Is there maybe something like onWindowClose (as oppesed to onUnload) which will do something only specifically when the window is closed, as opposed to just unloaded?

I hope this clarifies what I'm trying to say.

Thanks again!

~dmason165

Jona
04-08-2003, 03:37 PM
Maybe use self.close(); then open the window.

dmason165
04-08-2003, 03:46 PM
JONA!!!

It worked!!!

Thank you for all your help and stickin' out with me...even through our confusing times:P

~dmason165

PS. Are you good with cookies?

dmason165
04-08-2003, 03:49 PM
Jona,

I told a lie:( It almost worked. The only problem is that the page will still open even if the user selects NOT to close the welcome page.

Any suggestions?

~dmason165

Jona
04-08-2003, 03:50 PM
I'm good with anything I can be... But I can guess you need help on a cookie script, too, eh? :p Sure, what's the problem? :D

Edit: It didn't work? Let me think for a minute...

dmason165
04-08-2003, 03:54 PM
Jona,

You are truly a doll!

I have to get ready to leave my CPU, but I will post tomorrow (or tonight if I can) on my cookie problem (I can't tell you how much help you will be if you can get me through that!).

About the previous problem, can I put a script in the page being opened that will close itself if the welcome page is still open?

Talk to ya lata!

~dmason165

Jona
04-08-2003, 03:55 PM
I have tested this and it works:

<html><head><script>
function PostWelcome(theURL,winName,features) {
var agree=confirm("Confirm your decision.\nClick OK to open the homepage to this site.\nClick CANCEL to exit.");
if(agree){
self.close();
window.open("Hom.htm");
} else { location="somePage.html"; }
}
</script></head><body>
<input type=button onclick="PostWelcome();" value="Post">
</body></html>

dmason165
04-09-2003, 07:17 AM
The only thing that doesn't work is if the user selects no, when IE asks if he/she would like to close the current window, and selects NO, the other window is still opened.

What I would like, if it is possible, is to have the page open if and only if the Welcome window is CLOSED (not unloaded).

But if this is not possible, is there any way the opened window can check to see if the Welcome page (the page which opened it) is still open and if it is, close itself? That way the opened page will only remain open if the welcome page has been closed.

~dmason165

Jona
04-09-2003, 10:12 AM
I don't know what browser you're using, but in IE 6.0 the script I gave you works completely fine. You check if the parent window is open in the new window by putting code something like this in the new window: if(parent.closed){//if the parent window is closed; } else {//if it's open; }

dmason165
04-09-2003, 12:05 PM
Thank you so much Jona! Are you ready for me to post on my cookie questions?;)

Jona
04-09-2003, 03:51 PM
Yup. Post at will. :p