Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 根据用户选择关闭jsp页面_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 根据用户选择关闭jsp页面

Javascript 根据用户选择关闭jsp页面,javascript,jquery,ajax,Javascript,Jquery,Ajax,我有一个jsp页面,如果用户关闭页面,弹出框就会出现,询问他是否真的想关闭页面 如果他选择关闭页面,那么我需要使用ajax重定向到另一个jsp页面 我怎样才能达到同样的效果 sample.jsp <html> <head> <title>Refresh a page in jQuery</title> <script type="text/javascript" src="jquery-1.4.2.min.js"></s

我有一个jsp页面,如果用户关闭页面,弹出框就会出现,询问他是否真的想关闭页面

如果他选择关闭页面,那么我需要使用ajax重定向到另一个jsp页面

我怎样才能达到同样的效果

    sample.jsp
<html>
<head>
<title>Refresh a page in jQuery</title>

<script type="text/javascript" src="jquery-1.4.2.min.js"></script>

</head>

<body>

<h1>Stop a page from exit with jQuery</h1>

<button id="reload">Refresh a Page in jQuery</button>

<script type="text/javascript">

    $('#reload').click(function() {

        location.reload();

    });

    $(window).bind('beforeunload', function(){
        return '>>>>>Before You Go<<<<<<<< \n Your custom message go here';
    });

</script>

</body>
</html>
我有一个示例代码,当用户单击关闭按钮时询问用户,但当按下刷新、提交或清除按钮或任何其他按钮时,会弹出此消息

任何人都可以修改给定的代码或实现相同功能的任何新功能

    sample.jsp
<html>
<head>
<title>Refresh a page in jQuery</title>

<script type="text/javascript" src="jquery-1.4.2.min.js"></script>

</head>

<body>

<h1>Stop a page from exit with jQuery</h1>

<button id="reload">Refresh a Page in jQuery</button>

<script type="text/javascript">

    $('#reload').click(function() {

        location.reload();

    });

    $(window).bind('beforeunload', function(){
        return '>>>>>Before You Go<<<<<<<< \n Your custom message go here';
    });

</script>

</body>
</html>
sample.jsp
在jQuery中刷新页面
使用jQuery停止退出页面
在jQuery中刷新页面
$(“#重新加载”)。单击(函数(){
location.reload();
});
$(窗口).bind('beforeunload',function(){
出发前返回'>>>>>>>
您应该在刷新之前解除事件绑定

$('#reload').click(function() {
    $(window).unbind("beforeunload");
    $(window).unbind("unload");
    location.reload();

});