Click here to Skip to main content
15,922,584 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi,

I'm in a situation to write a script only in my page.aspx.cs
i'm including below lines in my code
C#
$( window ).on('unload',function() {
  alert( 'Bye now!' );
});


its throwing an alert after closing my browser. so, i'm using

C#
$( window ).on('beforeunload',function() {
  return 'Are you SURE!' ;
});


which is not working
could any one help me, i want a warning before closing my browser and it should be shown only when red cross button at top right is pressed not when page is refreshed or redirected to another page.
Help me Please.
Posted
Updated 29-Oct-13 3:12am
v3
Comments
sumanth n 29-Oct-13 9:43am    
TrushnaK, CodeBlack
thanks,

i'm writing my script under aspx.cs

so its throwing an error when i use double quotes,

im writing my script as

string str_Script = @"
<script type='text/javascript'>
</script>"

could you help me!!!

try this javascript function:-

XML
<script type="text/javascript">
    var close = true;
    window.onbeforeunload = function(){
    if (close) {
        return "Hope you like it."
    }
    }
    function unhook() {
    close=false;
    }
</script>
 
Share this answer
 
Try with below code :

JavaScript
window.onbeforeunload = function () {
           var r = confirm("Are you sure ?");

           if (r) {
               alert('You pressed "OK"');
           } else {
               alert('You pressed "Cancel"');
           }

           return r;
       };
 
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