Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
i m using onbeforeunload function to get the pop up before navigate away from the
current page pop up will show below message,

------------------------------------------------------
Are you sure want to navigate away from this page !
!
< my customize Message >

Press OK to continue OR Cancel to stay on the page

-------------------------------------------------------


these three lines are coming middle one is my customise line

now i want to show only my customize message what to do?

i searched on net but didn't got any answer.



OR

when i not passing my customize message there is a more space in line 1 and line 3
if i want to remove that space what should be done.





thank you in advance its urgent...



here is my code
-----------------------------

C#
function OnClosWindow() {
        if (window.confirm('Are you sure you want to navigate away from this page?\n\nYou have not submitted any narrowings for the candidates.\n\nPress OK to continue, or Cancel to stay on the current page.')) {
            reload = true;
            return true;
        }
        else {
            return false;
        }
    }
    var reload = false;
    function resetreload() {
        reload = true;
    }
    function isNavigating() {
        //alert(reload);
        if (!reload) {
            reload = false;
            return "You sures";
        }

    }
    window.onbeforeunload = isNavigating;
--------------------------------------------------------


<a href="http://www.google.com">Navigate HyperLink</a><br />
<asp:Button ID="Button2" runat="server" Text="No Navigate Away" OnClientClick="return resetreload();" />
<asp:Button ID="Button1" runat="server" Text="Navigate Away" OnClientClick="return OnClosWindow();" />



please help need solution
Posted
Updated 31-May-12 21:18pm
v2

1 solution

Hi there,

If you could post your JS code we could have a look and see what's wrong for you. What browser were you viewing the message in? Since there is no formal specification for this some of the browsers add the extra lines you are talking about as mandatory and so you just have to make your message fit with it. Have a look at this page for more info on how to set this up properly:
https://developer.mozilla.org/en/DOM/window.onbeforeunload[^]

You need to assign the onbeforeunload property to a function that returns a string, not just directly to a string as many believe. Also, you cannot handle it as an event, as many people try to do.

Hope this helps,
Ed

Edit: To post your code, use the Improve Question link on the bottom right of your question.
 
Share this answer
 
v2
Comments
Sandeep Mewara 31-May-12 4:00am    
Good suggestion 5!
Ed Nutting 31-May-12 4:02am    
Thank you :)
Raj7sam 1-Jun-12 3:22am    
im using IE 8
Raj7sam 1-Jun-12 3:24am    
please post your code here so that i can try it myself
Ed Nutting 1-Jun-12 4:00am    
You can adapt the message in this but the basic form is:
window.onbeforeunload = function (e) {
e = e || window.event;

// For IE<8 and Firefox prior to version 4
if (e) {
e.returnValue = 'Want to leave?';
}

// For Chrome, Safari, IE8+ and Opera 12+
return 'Want to leave?';
};

(I took this straight from the link I gave you really - it does work in IE8)
Ed

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