js实现用户关闭页面时提示是否离开此页面的方法

<script type="text/javascript">
  window.onbeforeunload = function(){
      return "您确定要退出页面吗?";
  }
</script>


效果图
js实现用户关闭页面时提示是否离开此页面的方法