关闭弹出窗口后执行操作


Perform action after a popup window is closed

在主页上,我有一个可以最初设置的计时器。当时间消失时,弹出窗口会显示必须完成的测验。我有一个变量$correctQuestions,用于存储该测验的正确答案数量。

我想要的是一个 PHP 函数,用于关闭弹出窗口并添加重新启动计时器的按钮,如果所有问题都回答正确,则在初始时间上增加 30 秒,然后删除 30 秒。怎么能做到这一点呢?

编辑:在计时器 PHP 文件中,我有一个按钮来调用函数以增加/减少 js 中计时器脚本的时间,还有一个按钮来启动计时器:

<button id="Start-Stop" onclick="clickButton();">START</button>

当时间关闭时,将出现弹出窗口,其中包含来自数据库的一组问题

下面是带有按钮调用的函数的脚本:

function clickButton()
{
  // Code which is not so relevant for my question
  document.getElementById("errorLabel").innerHTML = "";
  displayTime();
  document.getElementById("Start-Stop").innerHTML = "Stop";
  start = true;
  chosenTime = time;  
  timer = setInterval(tick, 1000);
  // Show the time left
  document.getElementById("initialTimeLabel").innerHTML = "Time until exercise:";
} // clickButton
function tick()
{
  if(time == 0)
  {
    clearInterval(timer);
    openWindow();
  }
  else
  {
    time = time - 1;
  }
  displayTime();
}
function openWindow()
{
  // Choose the selected module and popup an excercise page
  var module = document.getElementById("moduleDropdown");
  module = module.options[module.selectedIndex].text;
  var mylink = "ExercisePage.php?module=" + module;
  var windowname = "Questions";
  start = false;
  time = chosenTime;
  displayTime();
  document.getElementById("moduleDropdown").disabled = false;
  document.getElementById("initialTimeLabel").innerHTML = "Set an initial time:";
  document.getElementById("Start-Stop").innerHTML = "Start";
  var myWindow = window.open(mylink, windowname, "type=fullwindow,fullscreen=yes,height=screen.availHeight,width=screen.availWidth,left=0,top=0,resizeable=no,scrollbars=yes");
  myWindow.focus();
}

当我按下按钮关闭弹出窗口时,如果所有问题都回答正确,我希望我的计时器以 +30 秒(我有一个变量$correctQuestions来计算它们)重新启动,否则为 +30 秒。

启动弹出窗口后,例如

var myWindow = window.open("https://www.google.com", "Google", "width=800, height=600");

但是,如果您想检查弹出窗口是否已关闭

var interval = window.setInterval(function () {
  if (myWindow.closed) {
    // Do some stuf here as this will run when the popup has been closed
    alert("Child window closed");
    window.clearInterval(interval);
  }
}, 500);

如果您想在单击某些按钮时或在间隔后关闭弹出窗口

$myBtn.click(function () {
  myWindow.close();
  // other code here to reset your timers etc
});