1

I am working on quiz site where there'll be 25 questions which user have to answer one by one. Once quiz starts, user can not go back and refresh the page, if they do so then i've to complete the quiz for them. How to detect browser back button, enter button and page refresh event in jquery? Any help will be appreciated. Thanks in Advance

Tani Partner
  • 117
  • 2
  • 11
  • Only one of those is feasible. For this type of thing you really should use some server side validation. – CollinD Feb 27 '16 at 06:05
  • can u please tell me how to do server side validation? – Tani Partner Feb 27 '16 at 06:06
  • It looks like this kind of binding from another answer might work. https://stackoverflow.com/questions/11379411/how-can-i-detect-the-back-forwards-buttons-being-clicked-when-using-history-js – Joel Feb 27 '16 at 06:07

1 Answers1

0

For back button event please check below code

jQuery(document).ready(function($) {

  if (window.history && window.history.pushState) {

    window.history.pushState('forward', null, './#forward');

    $(window).on('popstate', function() {
      alert('Back button was pressed.');
    });

  }
});

For browser backward compatibility I recommend: history.js

Dhaval Patel
  • 1,076
  • 6
  • 19