ฉันต้องการยืนยันก่อนที่ผู้ใช้จะออกจากหน้านี้ หากเขาบอกว่าตกลงก็จะเปลี่ยนเส้นทางไปยังหน้าใหม่หรือยกเลิกที่จะออก ฉันพยายามที่จะทำให้มันกับการโหลด
<script type="text/javascript">
function con() {
var answer = confirm("do you want to check our other products")
if (answer){
alert("bye");
}
else{
window.location = "http://www.example.com";
}
}
</script>
</head>
<body onunload="con();">
<h1 style="text-align:center">main page</h1>
</body>
</html>
แต่มันยืนยันหลังจากปิดหน้าไปแล้ว? ทำอย่างไรให้ถูกต้อง?
มันจะดียิ่งขึ้นถ้ามีคนแสดงให้เห็นว่าทำอย่างไรกับ jQuery