Home > other >  Is there a way to execute function before unloading razor view of _Layout asp.net core
Is there a way to execute function before unloading razor view of _Layout asp.net core

Time:05-09

I know that I can bind handler to onbeforeunload event and execute something before full page unload. But is there a way to do this on razor view of _Layout?

CodePudding user response:

Yes,it could,If you add the js codes in _layout,when you leave the page,it would work I added the codes in my layout:

<script type="text/javascript">
        window.onbeforeunload = function (){
            return("");
        }
    </script>

when I leave the page, a dialogue pop out enter image description here

You could share your codes if you have problems when you add the function of onbeforeunload

  • Related