有什么方法可以检测用户是否点击地址栏上的Enter键?
如果用户单击ctrl + F5或Ctrl + r,我正在检测浏览器刷新, 但我想检测用户何时进入地址栏并点击Enter。
@HostListener('window:beforeunload', ['$event'])
@HostListener('window:keydown', ['$event'])
beforeunloadHandler(e) {
const r = "keyR"
if (e.code == "F5"
|| (e.ctrlKey && e.code == r)
|| (e.ctrlKey && e.shiftKey && e.code == r)) {
console.log('Refresh occurred')
} else if (e.type === "beforeunload"
|| e.type === "unload") {
console.log('Browser window is closed')
}