Click here to Skip to main content
15,943,742 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi.. Gud mrng.

I have d requirement that if the user clicked refresh button or f5 I need to redirect the page to Login page..

I had done with browser close using
$(window).bind('beforeunload', function (e) {
//my logiic

But i failed in the refresh or pressing f5..

if u know .
plz help me..

Updated 30-Jul-17 10:21am

Link 1

Link 2

Check the above 2 links
Share this answer
check this[^]

Please check the above solution, it has used javascript, but i guess this would solve this problem of yours.
Share this answer
I got the solution by using below code...
I tested in IE,Chrome and FireFox...
It works great for me..

@*//Script for detect Browser refresh..
<script type="text/javascript">

         var logoutFlag = true;
         var success = false;

         $(document).ready(function () {

             $("a,:input").click(function () {
                 logoutFlag = false;

             var myEvent = window.attachEvent || window.addEventListener;
             var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload';

             myEvent(chkevent, function (e) {

                 if (logoutFlag == true) {

                         type: "POST",
                         traditional: true,
                         dataType: "json",
                         async: false,
                         url: '@Url.Action(UrActionName, UrControllerName)',

                         success: function (data) {

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

Share this answer
<div id='iconos'></div>

function refreshcontrol(){
'use strict';
var keyCodes = {
  116 : "f5 "
var body = document.querySelector('body');
body.onkeydown = function (e) {
  if ( !e.metaKey ) {
	var finsesion=1
$.post('finsesion.php',{action: "iconos", finsesion:finsesion},function(res){

-------------PHP finsesion.php-----------

header('Location: login.php');
Share this answer
Graeme_Grant 30-Jul-17 19:38pm    
Any reason that you are answering a 3+-year-old question that the OP has already accepted answers to? Please don't answer tombstoned questions! Only answer those that are current and requiring help.

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