Skip to content

阻止用户离开页面时确认的正确姿势 #48

Open
@yangweijie

Description

@yangweijie

stackoverflow 说unload 中alert被浏览器 阻止了,只能在beforeunload 中返回字符串。

$(window).on('unload', function(){
   console.log('将离开页面');
});

$(window).on('beforeunload', function(){
   return '你确定要离开该页面吗?';
});

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions