JS implements closing the current page without popping up a prompt box

  • 2021-06-29 10:10:11
  • OfStack

This article provides an example of how JS implements closing the current page without popping up a prompt box.Share it for your reference, as follows:

Close the current page and open a new one (without prompting)


function closeWinAndOpen(url) {
  var sWinName = "LR"+parseInt(Math.random() * 100000000);// Processing with random numbers WinName
  window.open(url,sWinName, 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes,copyhistory=yes');
  closeWin();
}

Close the current page:


function closeWin() {
  window.opener=null;
  window.open('','_self');
  window.close();
}

Close parent page:

Response.Write("<script>window.top.opener=null;window.parent.close();</script>")

(window.top.close() also works)

Set window.opener=null to not show: "The page you are viewing is trying to close the window, do you want to close the window?"

More readers interested in JavaScript-related content can view this site's topics: Summary of JavaScript Switching Effects and Techniques, Summary of JavaScript Finding Algorithmic Techniques, Summary of JavaScript Animation Effects and Techniques, Summary of JavaScript Errors and Debugging Techniques, Summary of JavaScript Data Structure and Algorithmic Techniques.Summary of JavaScript Traversal Algorithms and Techniques and Summary of JavaScript Mathematical Operation Usage

I hope that the description in this paper will be helpful to everyone's JavaScript program design.


Related articles: