[英]submit form when user clicks browser back button
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. window.onbeforeunload这对我不起作用。
Just use this code and this will cover all state of page leave or close... 只需使用此代码,这将涵盖所有页面离开状态或关闭...
<script>
window.onbeforeunload = function() {
$('#movevalue').submit();
return true;
};
</script>
try this: 尝试这个:
$(function () {
if (window.history && window.history.pushState) {
window.history.pushState('', null, '');
$(window).on('popstate', function (id) {
$('#movevalue').submit();
});
}
}); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.