为了账号安全,请及时绑定邮箱和手机立即绑定

jQuery $(window).unload() 尝试关闭窗口时失败

jQuery $(window).unload() 尝试关闭窗口时失败

PHP
慕桂英546537 2022-12-23 13:21:34
我正在用较小设备的全屏覆盖替换模型窗口。假设 $(window).hide() 不必要地将该窗口保留在内存中,我正在尝试使用 $(window).unload(),但它没有按预期工作。我使用一个 PHP 变量作为脚本名称,因为不同的脚本将使用此实用程序。在进一步探索时,我发现 unload() 已被弃用,并且可能一开始并不打算以这种方式使用。除了 $(window).hide 之外,我不知道还有什么选择。这是完整的代码<?php    session_start();    $Script = $_REQUEST[Script];?><!DOCTYPE html><html>    <head>        <script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>        <style type="text/css">            body {width:100%; padding:0; margin:0; background-color:#FFFFFF;}            .Leave {position:absolute; top:20px; right:20px;}        </style>    </head>    <body>        <img class="Leave" src="images/CloseButton2.png" alt="close">        <div id="ScreenOverlay"></div>        <script>            $(document).ready(function()            {                $("#ScreenOverlay").load("<?PHP echo($Script); ?>", function(response, status, xhr)                {                    if(status == "error")                    {                        console.log(msg + xhr.status + " " + xhr.statusText);                    }                });                $(".Leave").click(function()                {                    $(window).unload();                });            });        </script>    </body></html>
查看完整描述

1 回答

?
哆啦的时光机

TA贡献1779条经验 获得超6个赞

预期的行为是什么?您不会通过调用卸载从内存中卸载窗口。卸载需要一个事件处理程序

也许你想要

$(".Leave").click(function()  $(window).close() });

假设你自己从同源脚本打开了窗口

没有 window.hide 这样的东西

如果您只想卸载的内容,$("#ScreenOverlay")则执行$("#ScreenOverlay").empty()$("#ScreenOverlay").remove()


查看完整回答
反对 回复 2022-12-23
  • 1 回答
  • 0 关注
  • 201 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号