Skip to content

Instantly share code, notes, and snippets.

@ixqbar
Created September 17, 2019 10:07
Show Gist options
  • Save ixqbar/96cbf8fdbb104d4490d0cbbeb3116858 to your computer and use it in GitHub Desktop.
Save ixqbar/96cbf8fdbb104d4490d0cbbeb3116858 to your computer and use it in GitHub Desktop.
页面离开提示
(function(){
	// 关闭窗口时弹出确认提示
	$(window).bind('beforeunload', function(){
		// 只有在标识变量is_confirm不为false时,才弹出确认提示
		if(window.is_confirm !== false)
			return '您可能有数据没有保存';
	})
	// mouseleave mouseover事件也可以注册在body、外层容器等元素上
	.bind('mouseover mouseleave', function(event){
		is_confirm = event.type == 'mouseleave';
	});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment