发送被按下的键来归档 [英] Send which key that was pressed to file

查看:74
本文介绍了发送被按下的键来归档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题想要得到帮助.首先,我想知道如何检测按下的键,然后将其发送到另一页或计算机上的另一个文件或多或少的另一个文件中?不重定向我已经知道该怎么做,但更像是将按键发送到结果文件"之类的东西.到目前为止,我有一个按键重定向到下一页/文件,当用户按下按钮时,它将charCode记录到控制台.但是我希望它将密钥发送到另一个文件,而不是将其发送到控制台.到目前为止,这是我的代码:

Hi I got a question that I would like to get some help with. First I was wondering how to detect which key that was pressed and then after that send the key that was pressed to another page or more or less another file that I have on my computer ? Not redirecting I already know how to do that, but more like send the keypress to a "result file" or something like that. So far I got a keypress that redirects to next page/file and when the user presses the button it logs the charCode to the console. But I want it to send the key to another file instead of sending it to the console. Here is my code so far:

jQuery:

document.onkeypress = function(b) {
         b = b || window.event;
         var charCode = b.charCode || b.keyCode,
         character = String.fromCharCode(charCode);

console.log(charCode);
window.location.href="Test3.html";
};

我得到了b和r中的两个.如果有可能用jQuery或JavaScript做到这一点,那就太好了,但是如果有另一种用另一种语言来做到这一点,我需要详细的描述.

And I got two of those b and r. If there's a possible way to do it in jQuery or JavaScript it would be awesome, but if there's another way to do it in another language I need a detailed description.

推荐答案

window.location.href="Test3.html/?charCode=" + charCode;

这将使您的页面"Test3.html"具有对GET参数"charCode"的访问权限.尽管您可能想使用服务器端语言来做一些有用的事情,但是由于IMO,从javascript操作GET参数有点麻烦.

This will give your page 'Test3.html' access to the GET parameter 'charCode'. Though you'd probably want to use a server-side language to do something useful with it, since IMO it is a bit of a hassle to manipulate GET parameters from javascript.

这篇关于发送被按下的键来归档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆