How can I check with jQuery if a specific word is entered in the browser?

This is ridiculous, I want to display a specific div on a website only if the secret word is printed on this page (forms are not present). What is the easiest way to do this using jQuery? Are there any plugins? Thanks in advance cheers Tabaluga

+5
source share
6 answers
if ( window.addEventListener ) {
        var kkeys = [], konami = "68,73,78,78,69,82"; //this spells dinner
        window.addEventListener("keydown", function(e){
                kkeys.push( e.keyCode );
                if ( kkeys.toString().indexOf( konami ) >= 0 ) {
                    // run code here    
                    $("#text").hide().fadeIn("slow").html('Now the website will appear.');
                }
        }, true);
}

you can check what exactly the letters do:

if ( window.addEventListener ) {
    window.addEventListener("keydown", function(e){
        $("#text").append(e.keyCode + " ");
    }, true);
}
+7
source

try using js-hotkey jquery plugin :

$(document).bind('keydown', 's+e+c+r+e+t', fn);

You can also check KonamiCodeWebsites to find out how it works:

- (UP + UP + DN + DN + LFT + LFT + RGT + RGT + B + A), !

+2

javascript:

var typedWord = '';
window.addEventListener('keypress', function(e){
  var c = String.fromCharCode(e.keyCode);
  typedWord += c.toLowerCase();
  if(typedWord.length > 4) typedWord = typedWord.slice(1);
  if(typedWord == 'jogo') alert('JOGO');
});

http://codepen.io/rafaelcastrocouto/pen/xeGps

+2

HTML:

<div style="display: none" class="secret">Correct password!</div>

JS:

var pass="password";
var typed="";

$(document).keypress(
    function (e) {
       typed += String.fromCharCode(e.which);

       if (typed===pass) {
           $('.secret').show();
       }
    }
);

Javascript, :

$(document).keypress((function(e) {
    var pass = "password";
    var typed = "";

    return function(e) {
        typed += String.fromCharCode(e.which);

        console.log(typed);
        if (typed === pass) {
            $('.secret').show();
        }
    };
})());
+1

, .

$(document).ready(function(){
    var currentKey = 0;
    var validKeyArray = [22,23,24]; //list of valid keys to listen to in order
    $('body').keyup(function(event) {
        if (event.keyCode == validKeyArray[currentKey]){
            currentKey ++;
        } else {
            currentKey = 0;
        }
        if (currentKey == validKeyArray.length){
           // SUCCESS! Do your magic div right here!
           // console.log('SUCCESS!');
        }

    });
});
0

, : http://jsfiddle.net/Akkuma/CGmnw/

. , , , . , , .

, .

0

All Articles