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
@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?
I have a testing site at http://visualsgd.net/Testing/TurnAround/index.html
@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/'); } $(document).keyup(function(e) { if (e.which === 27) { getAway(); } });
jsFiddle because CodePen was being a weirdo. I hope this helps.
@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!
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
@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?
I have a testing site at http://visualsgd.net/Testing/TurnAround/index.html
@Cathyk : First, if you plan on using jQuery then you need to reference it locally or through a cdn. Add this:
I slightly modified your code as well as included an example.
jsFiddle because CodePen was being a weirdo. I hope this helps.
@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!