I have a situation here. I have a form which contains hidden value. When user clicks the browser back button then the form should be submitted. I have controlled the back space button but haven't found a solution for browser back button. Here is my code.
Form
<form id="movevalue" action="/media" method="post">
<input type="hidden" id="pagedetail" name="pagedetail" value="<?php echo $pagenumber; ?>" />
<input type="submit" value="" style="display:none" />
</form>
At the end of page this is my script.
script
<script>
$(function(){
$(document).bind("keydown keypress", function(e){
if( e.which == 8 ){ // 8 == backspace
$('#movevalue').submit();
}
});
});
window.onbeforeunload = function(evt)
{
if (typeof evt == 'undefined')
$('#movevalue').submit()
}
</script>
window.onbeforeunload this not work for me.