Deprecated: parse_url(): Passing null to parameter #1 ($url) of type string is deprecated in /www/wwwroot/blog_qqvbc_com/usr/plugins/Access/Access_Core.php on line 339

Deprecated: parse_url(): Passing null to parameter #1 ($url) of type string is deprecated in /www/wwwroot/blog_qqvbc_com/usr/plugins/Access/Access_Core.php on line 392

Deprecated: parse_url(): Passing null to parameter #1 ($url) of type string is deprecated in /www/wwwroot/blog_qqvbc_com/usr/plugins/Access/Access_Core.php on line 394
JS防止窗口被意外关闭 - Joyber 的博客


        var updateStatus = true
        window.addEventListener('beforeunload', function (event) {
            // 取消关闭窗口事件
            if (!updateStatus) return true
            event.preventDefault();
            // Chrome 需要返回一个空字符串
            event.returnValue = '当前数据有更新还未保存,是否要离开?';
            return '当前数据有更新还未保存,是否要离开?'
        })

标签: none

添加新评论