Grow your CSS skills. Land your dream job.

Keyup not working

  • # December 18, 2012 at 11:37 pm

    I’m a novice when it comes to javascript and am trying to get the escape key to exit site quickly, following the http://css-tricks.com/website-escape/ post and using the script. Everything is working except the following code:

    $(document).keyup(function(e) {
    if (e.keyCode == 27) { // escape key
    getAway();

    Any help greatly appreciated.

    Thanks!
    Cathy

    # December 18, 2012 at 11:41 pm

    @Cathyk Hi. I’m not that familiar with Javascript either but do you have a link to your site so I can see if the console is throwing an error?

    # December 18, 2012 at 11:51 pm

    I have a testing site at http://visualsgd.net/Testing/TurnAround/index.html

    # December 20, 2012 at 1:28 am

    @Cathyk : First, if you plan on using jQuery then you need to reference it locally or through a cdn. Add this:

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

    I slightly modified your code as well as included an example.

    function getAway() {
    window.open('http://omg.yahoo.com/news/','_newtab');
    window.location.replace('http://omg.yahoo.com/news/');
    }

    $(do​cument).keyup(function(e) {
    if (e.which === 27) {
    getAway();
    }
    });​

    jsFiddle because CodePen was being a weirdo. I hope this helps.

    # December 20, 2012 at 1:51 pm

    @John: THANK YOU! As I stated, I’m a novice & didn’t have the link for jQuery. Once I placed that in the file, it works!

    Enjoy your holidays!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".