【问题标题】:Track typed words in address bar跟踪地址栏中输入的单词
【发布时间】:2015-02-16 20:14:26
【问题描述】:

我需要跟踪按下的键,因为这是一个输入输入很重要的实验。 我正在使用它来跟踪所有按下的键

function keypress(e)
{
   if (!e) e= event;
   var focused = document.activeElement;
   var a = String.fromCharCode(e.keycode);
}

function init()
{
    if (document.addEventListener)
    {
       document.addEventListener("keypress",keypress,false);
    }
    else if (document.attachEvent)
    {
       document.attachEvent("onkeypress", keypress);
    }
    else
    {
       document.onkeypress= keypress;
    }
}

function suppressdefault(e)
{
       if (e.preventDefault) e.preventDefault();
       if (e.stopPropagation) e.stopPropagation();
}
</script>

它工作得很好,但是如果用户在地址栏(写 url 的地方)写一些东西,它不会跟踪这些字符。

我一直在想,有什么方法可以在那里跟踪这些键类型吗?如果没有,有什么方法可以阻止用户在方向栏写任何东西?

【问题讨论】:

标签: javascript jquery html url


【解决方案1】:

你是说这个吧?

该栏不是网页的一部分,网页只能收听发送到网页的击键。所以你不能(无论如何你不应该)检测或停止这些击键。

但是你可以打开一个没有地址栏的窗口。 https://developer.mozilla.org/en-US/docs/Web/API/Window.open

window.open('http://www.example.com/', '_blank', 'location=no');

演示:http://jsbin.com/fisehihila/1/

在现代桌面浏览器中,它们确实会显示地址栏以防止网络钓鱼,但它不可编辑。

这里在Windows 7的火狐发布通道中是灰色的,可以选择,但是不能输入。

不过,这些窗口功能的选项在移动浏览器中的支持有限。

【讨论】:

  • 好主意,谢谢,除非出现更好的情况,否则我会接受这个
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-12-29
  • 2011-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-06
相关资源
最近更新 更多