how to get browser call back event
how to get browser call back event ?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Nilesh AvhadPosted Mar 19, 2014, 4:00 AM
You can do this as follows
We will store the current page URL in a session variable (say CurrentPageURL) on a page. When moved to another page, we will get that variable value and store it in a second session variable (say PreviousPageURL) and update the CurrentPageURL session variable with a new page URL. The ASP.NET straightforward code implementation is as follows:
//ASP.NET/C# code
if (Session["CurrentPageURL"] != null)
{
Session["PreviousPageURL"] = Session["CurrentPageURL"];
}
Session["CurrentPageURL"] = Request.Url;
On the client side, when the onbeforeunload event is fired, we will verify whether the JavaScript document.referrer value is the same as that of the session variable. If the value is the same, in other words the back button is clicked, then it will act accordingly.
function HandleBackFunctionality()
{
var previousPageURL = "<%= Session["PreviousPageURL"] %>";
if (document.referrer == previousPageURL)
{
alert("Its a back button click...");
//Specific code here...
}
}
-----------------------------------------------------------------------------------------
Please mark as answer if it solves your problem.
Thanks,
Nilesh