gpt4 book ai didi

javascript - 关闭弹出窗口时如何调用函数

转载 作者:行者123 更新时间:2023-11-30 06:30:06 26 4
gpt4 key购买 nike

我正在调用 Javascript window.open() 函数在弹出窗口中加载另一个 url。当用户关闭弹出窗口时,我希望调用 MyThanks() 函数。我该怎么做?

我的脚本:

<!DOCTYPE html>
<html>
<head>
<script>
function openWin(){
myWindow=window.open('http://facebook.com/ekwebhost','','width=600,height=400,left=200');
myWindow.focus();
}

function MyThanks(){
alert("Thanks");
}
</script>
</head>
<body>

<input type="button" value="Open window" onclick="openWin()" />

</body>
</html>

关于弹窗的使用:

您是否知道 Facebook 和 Twitter 仍然使用弹出窗口供用户点赞和关注。转到 http://www.ekwebhost.com然后单击 Facebook 的“赞”按钮或 Twitter 的“关注”按钮。为什么我不能根据自己的需要使用弹出窗口?

最佳答案

function openWin(){
myWindow=window.open('http://facebook.com/ekwebhost','','width=600,height=400,left=200');
// Add this event listener; the function will be called when the window closes
myWindow.onbeforeunload = function(){ alert("Thanks");};
myWindow.focus();
}

试试这个!

您可以将 function(){ alert("Thanks");}; 换成 MyThanks 来调用您的函数。

关于javascript - 关闭弹出窗口时如何调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18213521/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com