- This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
Viewing 5 posts - 1 through 5 (of 5 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Keyup not working
I’m a novice when it comes to javascript and am trying to get the escape key to exit site quickly, following the https://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.