我正在 try catch 人们在我的网站上搜索的字词(在 CTRL+F 之后)。有没有办法获取在 javascript 中实际搜索的内容?或者我的选择是重定向 CTRL+F 以聚焦/使用自定义输入?
最佳答案
来自 this answer
所以基本上你可以检测如果用户点击 Ctrl + F
然后继续检测
搜索字词。
window.addEventListener("keydown",function (e) {
# maybe you can add more detect for mac (Command + F)
if (e.keyCode === 114 || (e.ctrlKey && e.keyCode === 70)) {
# now detect all the key code here until "Enter"
# then you have the search term
}
})
关于javascript - 有没有办法在javascript中捕获网页搜索词(CTRL+F)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54799442/