Click to See Complete Forum and Search --> : Checking a windows status...
dmason165
04-21-2003, 09:38 AM
To all,
Still haven't been able to figure this one out.
How would I make a window close itself if it detects the window that called it is still open. Pretty simple question really...just not simple enough for me;)
Thanks!
~D
Charles
04-21-2003, 10:13 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>File "test1.html"</title>
<div>
<a href="test2.html" onclick="window.open(this.href); return false">test 2</a>
</div>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>File "test2.html"</title>
<script type="text/javascript">
<!--
if (opener) {
document.write('<a href="#">Close Test 1</a>');
document.links[document.links.length-1].onclick = function () {if (!opener.closed) opener.close()}
}
// -->
</script>
dmason165
04-21-2003, 02:19 PM
I'm almost there!
So far, I was able to extract from the code Charles gave me to get the page being opened to close itself if the page opening it, remained opened.
The code looks like this:
<script language="JavaScript" type="text/javascript">
<!--
if (opener.closed) {
} //do nothing
else {
self.close();
}
// -->
</script>
Now all I need is the page being opened, to STAY open if the page that opened it is closed. In other words, the "if" part of the script above is not doing what I would like it to do.
Any suggestions??
Thanks a bunch!
~Darron
PS. I guess I failed to clarify this in the first post, but this is all done automatically. As the page being opened, loads, it checks to see if the page that opened it is closed. If so, it remains open; if not, it closes itself. Hope that helps.
You've got it backwards.
if(opener.closed){ // if it's closed
self.close();
}
dmason165
04-21-2003, 05:56 PM
What I need, is for the window to close itself IF the OPENER is still open. I want one open or the other, not both and not neither.
Thanks again for your help. Let me know if you come up with anything.
~D
DrDaMour
04-21-2003, 05:57 PM
Originally posted by dmason165
To all,
Still haven't been able to figure this one out.
How would I make a window close itself if it detects the window that called it is still open. Pretty simple question really...just not simple enough for me;)
Thanks!
~D
this confuses me, say you open a window withthat code, then it woudl automatically close, because the window that called it would have to be open to open the new window (which would immediately close) am i wrong?
if(opener){self.close();}else{window.open("your_page.html");}
DrDaMour
04-21-2003, 06:06 PM
and if the new window closed it's opener liek jona's first script that still would be one or the other, just as you asked for.
dmason165
04-21-2003, 06:13 PM
it woudl automatically close, because the window that called it would have to be open to open the new window (which would immediately close)
I don't believe that is correct. Windows open other windows all the time just as they're being closed. The new window being opened doesn't exist on the condition of the window that opened it remaining open. Once a window is called to be opened, it's on its own, unless there is code in the opener to keep control over it.
Or perhaps you're misunderstanding me. The window opening the new window is closed in order to open the new window. However, I don't want them both open at the same time.
I have tested this and it almost works. If I open the new window by itself, it stays open, but with an error (the error is because it was opened without being called from another window).
If this makes it easier, the calling window cannot be closed unless the user selects "YES" when IE confirms if the user wants to close the window (because of security issues). If you don't know what I mean, let me know and I'll explain that part a little better. So, if the user selects "YES" the window closes itself and opens a new window...works beautiful. However, the new window will open even if the user selects "NO" when asked if they would like to close the window. What I need, is a script that will keep the new window from remaining open in the event the user selects "NO" when asked by IE if they would like to close the page.
I hope that helped.
Let me know if you need anymore info.
Thanks for your help.
~D
Why not just use <body onunload="window.open('file.html')">?
dmason165
04-21-2003, 06:17 PM
and if the new window closed it's opener liek jona's first script that still would be one or the other, just as you asked for.
I don't want the new window to close the opener. If the new window tried to do that, it would be restricted by IE's security again. You can only close windows with JS without permission ONLY if JS opened the window.
What I DO want, is for it to simply close itself if the opener is still open and to remain open if the opener is not open.
~D
dmason165
04-21-2003, 06:19 PM
Why not just use <body onunload="window.open('file.html')">?
Because then for every link followed on that page, it would try to open that one particular new window. However, there is only a new window opened for one particular link on the entire page. All other links use the same window.
~D
All right, I didn't want to have to be reduced to using this code, but...
<a href="file.html" onClick="opener=self;window.open(this.href);self.close();">
DrDaMour
04-21-2003, 06:26 PM
am i the only one who is complete lost here.
ok first i think you need some definitinos
window opener referse to the window that opened with window
so windowA.opener = windowB B opened A
first you said you want A to close if B is still open. Well what i said was B will always be open if A closes. As to the security feature, you can't circumvent that. Now what i think you could do is indirectly open the window of your coice
in your first window
<script>
var theURL = "";
function closer(aURL){
theURL = aURL;
window.close();
}
</script>
<body onunload="if (theURl != "") {window.open(URL,frame,attrib)}"
and all <A> in it shoudl do
<a href="javascript:closer(URLtoOPEN)">
dmason165
04-21-2003, 06:29 PM
<a href="file.html" onClick="opener=self;window.open(this.href);self.close();"> wouldn't work.
Here's why. The code I'm using to open the next page also detects if the user has JS enabled by using the onClick() event handler. My code looks like this:
<a href="../Home/GlobalFiles-/JavaScriptRedirect/1/%7E.htm"
Title="Click here to open the website's Homepage!
You must allow this window to close first.
Select YES when asked if you would like to close this window"
onClick="PostWelcome(); return false;">Welcome</a>
This is why I need a code that goes on the page being opened.
There HAS to be a way.
Thanks for all your help!
~D
We've disussed this for too long. Just post your whole code.. Or, I mean, take out all the content and stuff. Just the page with all the stuff necessary for us to go through. There must be something I'm missing.....
dmason165
04-21-2003, 06:36 PM
I think I have had things mistaken and must have confused you in the process.
I thought the "opener" was the window doing the opening. Kinda made sense. After reading your last post DrDaMour, technically I'm wrong with my terminology which is why my explanations are so written out.
With that being said, I'll reiterate. The window being open shall remain open if and only if the window which opened it, is in fact closed (if and only if the user selects "YES" when asked by IE if they would like to close the window).
I don't care to bypass the security with IE.
Very sorry about the confusion.
~D
Opener is the window that opened it. Example: window.open('file.html') and in file.html have: <a href="javascript:opener.close()">Close</a>. This will close the window that opened it. I think you were right in the first place, Dmason.
What does your PostWelcome(); function do? Can you post that code?
dmason165
04-21-2003, 07:02 PM
Sorry for responding so late....I got hungry.
My PostWelcome() function is as follows:
function PostWelcome(theURL,winName,features) {
var agree=confirm("Confirm your decision.\nClick OK to open the homepage to this site.\nClick CANCEL to remain on this page.");
if (agree) {
alert("When asked if you would like to close this window,\nyou MUST select \"Yes\" to enter the site.\n\nNote: You must allow this window to close first, before entering the site.");
self.close();
window.open("/DarronMason's/ProposalToAIGClaimsDepartment/Welcome/Home/1/%7E.htm",'','toolbar=no,resizable=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no');
}
}
~D
DrDaMour
04-21-2003, 07:05 PM
i pray for the day that the mod closes this thread......
you totally misunderstood what i said.
yes opener woudl be the one DOING the opening.
So you wan tthis
user goes to main website A, clicks a link, whcih opens website B in a NEW window. B's opener is A. You would like B to close A?
then in B do this
<script>
if(window.opener){
window.opener.close()
}
</script>
that is all
dmason165
04-21-2003, 07:08 PM
No. I don't want B to close A.
I simply would like B to close itself, if A remains open. If A IS closed, then B remains open. That's all.
I cannot put it any simpler than that.
~D
if(opener){self.close();}
That's what we said in the first place.
DrDaMour
04-21-2003, 07:14 PM
see that helps a lot
dmason165
04-21-2003, 07:21 PM
So now we can finally understand where I'm coming from.
if (opener) {
self.close();
}
This code works great if the opener remains open (page A)...in that page B closes itself. Great!! That's what I said when I first posted.
My problem is that the window closes itself, even if the opener (page A) is closed.
I think this is what prompted Dr's questions early in this thread. 'Tis why I told him that I didn't believe that an opener (page A) had to remain open in order for the new window (page B) to open and remain open.
I truly apologize for all this. I seriously did not think that this question would pose such a lengthy attempt at a solution. If someone CAN figure this problem out, I would be VERY thankful...I think Jona and Dr. would be too;) They prob. think I'm missing half my brain, but I'm not.
Again,
if (opener) {
self.close();
}
does not keep the new window (page B) open if the opener (page A) is closed.
~D
DrDaMour
04-21-2003, 07:24 PM
you never told us that window A would close itself, and that's super important
in B
<script>
if (window.opener){
self.close();
}
</script>
that should do it
dmason165
04-21-2003, 07:27 PM
ok, if you were to open B from A, A would still be OPEN, so B would automatically close. B woudl be open for about 3 seconds, and automatically close.
Perfect example of why this cannot be true:
Ever been to one of those annoying sites where when you close one window, it opens another as it's closing and on and on??? This is exactly what I'm doing...opening a window as the opener is closed. Only, because of that security issue, the opener could by chance remain open if the user doesn't follow directions and select "YES" to close the window when prompted by IE.
The rest I think you understand.
~D
dmason165
04-21-2003, 07:28 PM
you never told us that window A would close itself, and that's super important
I even posted my code.
~D
DrDaMour
04-21-2003, 07:29 PM
Dude, you never mentioned that A was closing itself, all of those pop-up chains use the onunload which is what we told you to use in the very beginning, in fact looking back there have been 3 answers already to this.
If A didn't close itself it would be what i described, and i was specific in mentioning that A was NOT closing itself.
and once you posted your code, we understood that A was closing itself, that's when your answer was forthcoming.......................see give us the INFO and we give you ANSWERS. It took you 20 posts to show us your code.
dmason165
04-21-2003, 07:37 PM
I apologize...I probably figured that it was implied that A would close itself since B would be checking to see if A was closed. Otherwise, why would it check to see if something happened that was never called for?
I have been saying that if when asked by IE if they would like to close the window blah, blah, blah... it's pretty obvious there that the window is trying to be closed. I then stated that IF the user did NOT select "YES", then A would remain open and B would then also be opened, creating the situation I don't want.
However, I don't think my question has quite been answered. I know you're getting extremely frustrated with this whole thing, but don't give up on me. If you were standing right next to me we would be on the same page. I apologize for the confusion and thank you tremendously for sticking this out when you could have easily ignored me.
~D
DrDaMour
04-21-2003, 08:01 PM
have you tried what i posted?
in B
<script>
if (window.opener){
self.close();
}
</script>
dmason165
04-22-2003, 07:11 AM
Thank you Dave!
This works perfectly!!
I was able to get the Timeout down to 100ms!
Thank you everyone for all your help and I apologize for all the confusion...it happens sometimes but I will try to reduce that as best I can in the future.
~Darron
dmason165
04-22-2003, 07:28 AM
Excellent warning!
I'll make the necessary adjustments!
Thanks again!
~Darron
No wonder I couldn't figure out what he was asking.... :rolleyes:
smoker2
04-28-2003, 09:08 AM
And what was wrong with having the page load in the original window ? If he wanted that window to close why did he want a new window to open with all the issues involved.
It looked like the home page anyway.
:confused:
jeez
dmason165
04-28-2003, 09:12 AM
FYI:
It's a local presentation in fullscreen and you wouldn't understand unless you saw it.
~D
smoker2
04-28-2003, 09:30 AM
And therein lies the problem.
Surely you don't provide the link on the main page until you want it to be used.
In which case, why does the second window need to know the status of the first.
If the link is designed to close the first window, then why waste time and code getting the second window to check if the first window is still open ?
Sounds like a recipe for a loop ...
Maybe if you opened the fullscreen window via script then you wouldn't get the Error that prevents it being closed without user intervention, and so wouldn't need to check for its existence.
You need to examine your motives for opening the second window.
Planning is the key, surely.
The best solution was the OnUnload solution. That wouldn't launch the second window until the first had been closed. No need to check for anything then.
dmason165
04-28-2003, 09:54 AM
Surely you don't provide the link on the main page until you want it to be used.
What do you mean by this?
If the link is designed to close the first window, then why waste time and code getting the second window to check if the first window is still open ?
The first window is not opened using JS and thus, can only be closed with permission of the viewer. As stated before, the presentation is in fullscreen and I don't want the Welcome page window and the presentation's window opened at the same time. That's how I planned it. FYI the fullscreen is opened with JS...look at the code "window.open..."
You need to examine your motives for opening the second window.
My presentation is exactly as I planned it to be now. My motives don't need any examination. You can't start the presentation in fullscreen because you cannot manipulate windows not opened with JS and the presentation was planned using fullscreen...did you have a better solution...I'll be pretty amazed if you do!
The best solution was the OnUnload solution. That wouldn't launch the second window until the first had been closed. No need to check for anything then.
This is NOT the best solution, because, as stated in previous posts, there are other links on the welcome page for the viewer to utilize so that the presentation is optimized for the viewer's experience (i.e. volume check, browser compatibility test, etc.). Clicking any of these other links would attempt to open the second window...how annoying would that be??
Have any other questions smoker??
~D
smoker2
04-28-2003, 11:30 AM
so you have a fullscreen window opened via javascript from the main page, to show the presentation, yes ?
Why do you need to have a third window opened at all ?
Are u closing the first window ? (the one that was used to launch the fullscreen window)
If not why do you need a third window ?
Why do you need a third window ?
Why do you need a third window ?
Why do you need a third window ?
If your original window is still open (and hidden due to the fullscreen second window) then redirect it to the main homepage at the same time as opening the fullscreen window. Then it sits there waiting until the fullscreen is closed.
If it isn't still open, use OnUnload in your fullscreen to open it .
You still don't need a window to check whether the last window is still open. You control whether that window is open in the first place.
Control is the key word here, and you seem to be reacting to problems instead of avoiding them in the first place.
If you have a link or a button in your presentation that allows the user to close the presentation then goes to the home page in a normal window, why do you show that link before the presentation is finished ? and so why does it matter if the presentation window is still open ? If you used onUnload in the presentation window then you could GUARANTEE that the presentation was finished before loading the new window !
All you seem to be doing is error checking for something you shouldn't have allowed in the first place.
Any other questions ?
LOL, there are 3 pages on this thread, and NO-ONE knew what you were even talking about until the last page.
still don't (care)
dmason165
04-28-2003, 12:15 PM
It's funny how the thread had pretty-much been dead until someone bored out of their mind and with nothing better to do than to post questions to a resolved issue...pretty sad.
Anyhow...
If not why do you need a third window ?
Dude, where are you getting "third window" from?? You need to read a little slower find out what the hell you're talking about BEFORE you post. There are two window: The Welcome page and the Home page. That's it...no third window.
If your original window is still open (and hidden due to the fullscreen second window) then redirect it to the main homepage at the same time as opening the fullscreen window. Then it sits there waiting until the fullscreen is closed.
It seems like you're trying to implement your way into a problem that's BEEN solved. Your way is not how I want it....do you not understand that I got the answer I needed?? Thanks for the time wasted.
If you have a link or a button in your presentation that allows the user to close the presentation then goes to the home page in a normal window, why do you show that link before the presentation is finished ?
Where are you getting that from?? When the presentation window is closed, there aren't anymore windows from my presentation open. And out of courtesy for others (in-case your lacking in that department) I give a link to close the presentation, because my purpose is not trap people in a fullscreen until it's finished. Would you want to be trapped on a page you couldn't close??
and so why does it matter if the presentation window is still open ?
Question answered.
If you used onUnload in the presentation window then you could GUARANTEE that the presentation was finished before loading the new window !
This makes no sense to me. Who said anything about loading a window when the presentation was finished...you're seriously confused.
LOL, there are 3 pages on this thread, and NO-ONE knew what you were even talking about until the last page.
Funny how its taken you more than what was there and you STILL don't know what I was talking about;)
still don't (care)
Then why are you still writing back??
Duh!!
~D