要判断页面是否在最近关闭标签打开,可以使用 window.performance.navigation
对象的 type
属性。如果 type
属性的值为 2
,则表示页面是在最近关闭标签打开的;否则,表示页面不是在最近关闭标签打开的。
以下是一个示例:
if (window.performance.navigation.type === 2) {
console.log("页面是在最近关闭标签打开的");
} else {
console.log("页面不是在最近关闭标签打开的");
}
在上面的示例中,我们使用 window.performance.navigation.type
属性来检查页面是否是在最近关闭标签打开的。如果 type
属性的值为 2
,则表示页面是在最近关闭标签打开的;否则,表示页面不是在最近关闭标签打开的。