当用户想要关闭网页时显示iframe

时间:2016-10-03 12:25:22

标签: javascript jquery html iframe

当用户想要关闭我的网页时,我需要显示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>

我可能错过了一些基本的东西......

1 个答案:

答案 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;                   
});