Click here to Skip to main content
15,906,467 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i know that the java script code for closing browser is:

XML
<script type="text/javascript" >
if (event.altKey==true && event.keyCode==0 )
{
}
</script>


but I want to use it form load event of a web form.

Please help me.


Thanking You

Mohd Wasif
Posted

You can't. When the code behind is being processed the page is not in the browser. Only after this processing is complete will the page sent to the browser. This is how ASP.NET works. What would be the point in sending a page to the browser and immediately closing it?
 
Share this answer
 
Comments
Mohd Wasif 19-May-11 7:52am    
then please let me know how to call a class object or session in this java script function

thanks in advance
Sergey Alexandrovich Kryukov 19-May-11 15:20pm    
Will you ask a separate question, some more detail and explanation what and what's the ultimate purpose of it?
(It won't be re-post, not at all! :-)
--SA
Sergey Alexandrovich Kryukov 19-May-11 15:19pm    
Good explanation, but please see mine as well.
--SA
P.S.: yes, a 5 for yours.
You cant...Don't waste your time...
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 19-May-11 15:18pm    
Great! My 5.
But also see my answer.
--SA
Considered putting a method call in the onload event of the page you return? To do this, set the ID of your page's body tag to something like 'BodyTag', give it a 'runat="server"' attribute and then, in C# it would be:

C#
BodyTag.Attributes.Add("onload", "window.close()");


This would close the browser as soon as the page is loaded, but! This is a very bad idea. This is a feature used by a lot of virus, malware and trojan distribution websites - you website will not be trusted and be very annoying if it closes a user's browser - 'the user (customer) ALWAYS knows best' as the saying goes, especially when it comes to closing their browser.

Hope this helps, even though I wouldn't consider using it :~

Ed :)
 
Share this answer
 
Just see EdMan196 or MatrixDud answer. Both are correct.Once it is loaded it automatically close the browser. However, I can't come up a scenario that anyone need such functionality.
 
Share this answer
 
You could close the browser window, but the user will get a warning message unless it's a window you opened.

The script would be
<script language="Javascript">
      window.close();
</script>


You could make it run be either setting the content of a asp.net label to be equal to that or response.write it or use RegisterStartUpScript
 
Share this answer
 
Comments
[no name] 19-May-11 19:01pm    
You are missing the point. The entire idea of closing the page once rendered is flawed. Just because you can doesn't mean you should.
You cannot. Bad idea, anyway. The customer knows better when to close a Web browser window. Even if you managed to achieve what you want, people would not use your site! What, do you want to make your user furious?

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900