[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 583
  • Last Modified:

ASP.NET and Javascript using a link to exit application

GRRR something so easy is just stumping me.

I have a applicaiton and one of the links says Exit.  When they clikck on it - I want the page/application to close.  

Waht am I doing wrong?
<ul>
       <li><a onclick='tryClose;'>Exit</a></li>
      <li><a href="../Help/help.htm">Help</a></li>
</ul>
 
<script type="text/javascript">
function tryClose()
{
Try
{
window.close();
}catch(e){
this.close();
}
 
}</script>

Open in new window

0
aninec
Asked:
aninec
  • 3
  • 3
1 Solution
 
sybeCommented:
javascript "window.close()" only works on windows that have been opened by javascript.
If you think about it, that makes perfect sense. You don't want people to create links to a page that closes your browser.
0
 
aninecAuthor Commented:
So how do I close the window when  user click Exit?  I am using ASP.NET and VB
0
 
sybeCommented:
You can not close a window which has been opened by the user. Forget that.

You could in stead redirect the user to an exit page.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
aninecAuthor Commented:
Can you clarify this for me?  Why cant I close this window?
This is a page that I created.  I have two links on it.  One opens a Help menu.  I want the other link to be Exit.  It basically closes the window.  This is the first page of an application  - the login page.  If the user wants to leave without logging in - I want to give them the option of Exit.  
0
 
sybeCommented:
It is a browser issue. Browsers do not allow a script to close a windows (with the exception of windows that have been opened by a script).

I explained the logic of it.
There are simply some things in browsers that are there to prevent abuse by people with bad intentions. Closing your browser is one of those abuses. Now you might not have bad intentions, but the browser has no way of knowing that.
0
 
aninecAuthor Commented:
I ended up doing this..  Gives me an Alert but works fine.

<ul>
            <li><a id="btnexit" onclick="window.close()">Exit</a></li>
            <li><a href="Help/help.htm">Help</a></li>
</ul>
0
 
sunithnairCommented:
The problem with your original code was this. You need to put it as a function call onclick='tryClose();'
<ul>
       <li><a onclick='tryClose();'>Exit</a></li>
      <li><a href="../Help/help.htm">Help</a></li>
</ul>
 
<script type="text/javascript">
function tryClose()
{
try
{
window.close();
}catch(e){
this.close();
}
 
}</script>

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now