test.html
<!DOCTYPE html>
<html>
<head>
<title>FabulousAirTickets.com</title>
<script src="test.js"></script>
</head>
<body>
<h2>FabulousAirTickets.com</h2>
<form action="#">
<p>
<label for="from">From:</label>
<input type="text" id="from">
<label for="to">To:</label>
<input type="text" id="to">
</p>
<p>
<label for="leavedate">DepartureDate:</label>
<input type="date" id="leavedate">
<label for="returndate">ReturnDate:</label>
<input type="date" id="returndate">
</p>
<p>
# of Adults:
<select>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</p>
<p>
<input type="submit" value="Find Flights!">
<input type="reset" value="Reset">
</p>
</form>
</body>
</html>
test.js
window.onbeforeunload = function() {
return "If you close this window, your flight choices will be lost!";
}
// 我在chrome下面用这个例子 完美支持
// 在firefox下面用这个例子 没有反应 -》因为firefox压根就不用函数返回的信息-》Firefox 不支持文字提醒信息
参考:http://blog.youkuaiyun.com/czkct/article/details/52092691