我正在用较小设备的全屏覆盖替换模型窗口。假设 $(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>
哆啦的时光机