kiddo_boy 2012-06-01 12:20
浏览 279
已采纳

火狐下刷新的问题

我想在页面刷新之前,然后页面的里一个表单先提交下。
[code="java"]window.onbeforeunload=function (event){

event = (event)?event:window.event;

if (event.clientX < 0 && event.clientY < 0  ||  event.altKey) {
    exitsystems();
}
 else {
    window.location.href = "<%=request.getContextPath() %>/page/user.do?method=closed"; 
    alert("1");
}

} [/code]
代码如上,else里面有个alert("1")看起来是多余的,如果在火狐上,不加上的话,就不会执行[code="java"]window.location.href = "<%=request.getContextPath() %>/page/user.do?method=closed"; [/code]
请教各位如何解决这个问题,alert("")肯定是不需要的,不然每次刷新页面都会跳个对话框出来。

  • 写回答

2条回答 默认 最新

  • iteye_10592 2012-06-01 13:41
    关注

    可能的问题是window.location.href赋值后,网页的执行是异步的,所以在关闭网页之前,来不及提交。alert是阻塞事件的,所以你能看到。

    改造的流程应该是,先中断当前事件执行,提交,然后再继续执行改事件。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?