<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Simulating Input Events</title>
<meta charset="UTF-8">
<script>
function checkLeave(){
event.returnValue="确定离开当前页面吗?";
}
</script>
</head>
<body onbeforeunload="checkLeave()">
</body>
</html>
onbeforeunload
方法用户关闭浏览器或者刷新页面的时候会提示,可是onbeforeunload只能放在body标签中。
请问一下在react中如何实现用户关闭浏览器或者刷新时提示相关信息
如下方式,不一定非得要放在body标签中