差分
このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
| study:javascript:dojo:prevent_paste [2009/07/08 02:39] – banana | study:javascript:dojo:prevent_paste [2010/03/19 15:15] (現在) – banana | ||
|---|---|---|---|
| 行 2: | 行 2: | ||
| ユーザー登録画面とかでパスワードとかメールの確認の貼り付け(Ctrl+V)を防止したい時があると思う。\\ | ユーザー登録画面とかでパスワードとかメールの確認の貼り付け(Ctrl+V)を防止したい時があると思う。\\ | ||
| 今回はその場面で役立つようなjavascriptコードを紹介する。 | 今回はその場面で役立つようなjavascriptコードを紹介する。 | ||
| + | {{keywords> | ||
| ===== code snippet ===== | ===== code snippet ===== | ||
| 行 8: | 行 9: | ||
| <!-- | <!-- | ||
| function onKeypress(e) { | function onKeypress(e) { | ||
| - | | + | var keycode = (e.which)? e.which: |
| - | if (e) { //Firefox, NN | + | if (e) { // Mozilla(Firefox, NN) and Opera |
| - | keycode = e.charCode; | + | |
| ctrl = typeof e.modifiers == ' | ctrl = typeof e.modifiers == ' | ||
| } else { // Internet Explorer | } else { // Internet Explorer | ||
| - | keycode = event.keyCode; | ||
| ctrl = event.ctrlKey; | ctrl = event.ctrlKey; | ||
| } | } | ||
| 行 50: | 行 49: | ||
| <!-- | <!-- | ||
| function onKeypress(e) { | function onKeypress(e) { | ||
| - | | + | var keycode = (e.which)? e.which: |
| - | if (e) { //Firefox, NN | + | if (e) { // Mozilla(Firefox, NN) and Opera |
| - | keycode = e.charCode; | + | |
| ctrl = typeof e.modifiers == ' | ctrl = typeof e.modifiers == ' | ||
| } else { // Internet Explorer | } else { // Internet Explorer | ||
| - | keycode = event.keyCode; | ||
| ctrl = event.ctrlKey; | ctrl = event.ctrlKey; | ||
| } | } | ||
| 行 95: | 行 92: | ||
| ===== reference ===== | ===== reference ===== | ||
| - | - [[http:// | + | - [[http:// |
| - | - [[http:// | + | - [[http:// |