使用PHP或Javascript检测页面刷新或新加载
问题描述:
如何使用PHP或Javascript在浏览器中检测选项卡关闭。换句话说,如何查找页面是刷新还是在新选项卡中打开。
How to detect tab close in browsers using PHP or Javascript. In other words, How to find if page is refreshed or opened in new tab. I am concerned about tab, not browser.
答
您可以为 window.onbeforeunload 事件。不过,您将无法检测该标签是否从JavaScript中关闭。
You can have a listener for the window.onbeforeunload event. You won't be able to detect if the tab is closed from JavaScript, though.