Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there jscript to close a browser?! 3

Status
Not open for further replies.

jfrost10

Programmer
Jun 3, 2001
2,004
0
0
CA
hey guys,

my client wants to be able to close the browser of a web application by clicking on a logout button thats on one of the asp pages in a frameset page (heh, hope that made sense).

Is there a way to do this using javascript or another means?!

Thanks,

Jack
 
Hey there...

This is what you need.


window.close();


Have Fun!
munkyCmunkyDU
 
Mental Note: pick up a javascript book to read over the weekend so i don't look like a complete idiot in these forums.
;)

Thanks guys!
:)

Jack
 
ps: visit for their quick refs

:)
penny.gif
penny.gif
 
Hey guys,

Just tried both versions of the code, and neither worked. Tell me if I'm missing something here:
in my image button, I have this within the img tag:
onclick="return IMG1_onclick()"
and up in my script tags I have this:
function IMG1_onclick() {
window.close
}
But when I click on img1, it doesn't close the window. This page is in a frame, does that matter any?

Thanks,
Jack
 
window.close();

forgot your parens

that looks suspiciously like vbscript, though. I'm not sure that's that syntax for vbscript. It's javascript.

:)
penny.gif
penny.gif
 
Or just write it as the image attrib as follows:

Code:
onclick="javascript:window.close();"
 
Don't log out in this way, this may not set the user's session off.
(although the user session will be off automatically after the default session timeout
if the user does not request any pages in that period)

Plus, by using window.close(), the browser will still ask you whether you want to
close that window, which is annoying.
 
Darn, you're right: it does prompt me. Is there a way to get it to work without the prompt?!

Jack
 
The only time you won't get the prompt is if you are closing a window that your application has opened via

window.open()

At that point, your application is more or less considered the "owner" of that window and so you can close it whenever you want. Otherwise, your user is the owner and they will get the prompt.

A side note, though, I've recently been saddled for developing a site for Nutscrape 6.2, and I receive no such prompt with that browser, even if closing the parent window. An oversight, probably. It's a security measure so us developers don't go closing their browser windows at our whim. I mean, you could (with enough algorithms) figure out what windows they had open, and just close them all if you wanted to.

You'll always get it in IE, though. No way around it.

penny.gif
penny.gif
 
Hey Link,

question for ya:
The only time you won't get the prompt is if you are closing a window that your application has opened via
window.open()

I have a logon screen. If the user is verified, it forwards to just a dummy page. All this page does is open the portal page I have set up, but with all the edits done with window.open(blah). Then the dummy closes itself. Now, according to what you're saying, I shouldnt' be getting the prompt, since the window I'm trying to close has been accessed by a response.redirect. Maybe an IE6 bug or trait?

jack
 
No, it's not a bug.

You said:
since the window I'm trying to close has been accessed by a response.redirect


you also mentioned window.open(), but I suspect that you have opened a new window, which is where you want your user to stay, and want to close the one they came in on.

In this scenario, you would be allowed to close the one they stay on, but not the one they came in on.

Response.redirect has no effect on whether you can close the window or not... it's still the original instance of the browser that they surfed in on, and therefore you cannot close it.

Is that any clearer? I'm starting to confuse myself now. ;-)
penny.gif
penny.gif
 
You nailed it!
:)

that is exactly what I'm trying to do. So no go eh? K, well let me throw a different slant: is there any way (other than a .hta file) to set the options like toolbar visible, status visible, etc., without using window.open? Is there some sort of browser object model i can access through javascript/vbscript?

Jack
 
Hmmm... wish I knew.

I bet if you posted it over in the javascript forum, they could tell you if there is a way.

window.open() is the only method I'm aware of.
penny.gif
penny.gif
 
Yeah, I did a post over there as well. Thanks link, I'll let you know if I figure a way around it.
:)

Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top