Click here to Skip to main content
14,738,282 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi.. I wrote the below script in my master layout for browser refresh and close..
I need to log out the user in both scenarios and below function works well..

<script type="text/javascript">

    var refresh = true;
    var success = false;

    $(document).ready(function () {
        $("a,:input").click(function () {
            refresh = false;
        });


        //Script for Browser refresh and close...
        var myEvent = window.attachEvent || window.addEventListener;
        var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload';

        myEvent(chkevent, function (e) {
            if (refresh == true) {

                $.ajax(
                {
                    type: "POST",
                    traditional: true,
                    dataType: "json",
                    async: false,
                    url: '@Url.Action("MyActionMethod", "MyController")',


                        success: function (data) {

                            if (data == "Success") {
                                success = true;
                            }
                        }
                    });

                }
            });

        });
</script>


In my content view i have the anchor tag like follows.. and clicking the link it vl redirect to respected url.. But when I m cliking that link first it fires the refresh_close related function which exist in my master layout.. I don't want to fire that function when clicking the link..

This is my anchor

I need to restrict calling beforeunload event while cliking anchor..

How can I accomplish this..

Thanks in Advance..
Honey..
Posted
Updated 6-Nov-14 18:38pm
v3

1 solution

<a id="aTest" href="GoogleMapsAPITest.aspx" onclick="return MyFunction();">Test Here !</a>


function MyFunction() {
  //add logic here to conditionally return true or false
  // false means no reloading.
  return false;
}


Hope this makes sense for you.
   

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