当用户想要关闭我的网页时,我需要显示iframe。我尝试使用jQuery(我真的不擅长jQuery),但我甚至无法在浏览器的选项卡关闭之前显示消息。我试过了:
<script>
$(window).bind('beforeunload', function(){
return "Do you really want to leave now?";
});
</script>
也尝试了
<script type="text/javascript">
$(window).on('beforeunload', function() {
return '....';
});
</script>
我可能错过了一些基本的东西......
答案 0 :(得分:1)
显示iframe代码:
window.onbeforeunload = function () {
$("#dialog").load("iframecontent.htm").dialog({dialogoptions});
};
显示消息:
window.onbeforeunload = function () {
return "Do you really want to close?";
};
或强>
window.addEventListener("beforeunload", function (e) {
var msg= "\o/";
(e || window.event).returnValue = msg;
return msg;
});