1

My apologies if this seems a bit of a daft question but I have a non crucial application that I have built using PHP, HTML, etc. to maintain certain aspects of my website.

It would be really nice if i could someone include a custom set of navigation controls or short cut keys within this.

At the moment I rely heavily on various links and buttons or inputs to navigate through the options and process the various functions.

I was wondering and after much thought and searching have not seemed to find any conclusive evidence in support or not in support of what i had in mind.

So basically, if i was on a certain page within the app and there would be an option that would say "Back" and I would click it to return to the previous section.

Would it be possible to bind say for instance the escape key to this link or rather the action of changing the header to xxxxx location.

If i could bind the left arrow to a back header location and the right arrow to a forward header location, it would be a god send and make things so much easier!

If anyone would be able to suggest whether this is possible or not I would really appreciate that. If this is possible, please point me in the direction of what i am actually looking for, thank you!!

Also, any suggestions, input, advice, feedback or other would be welcomed!

Craig van Tonder
  • 7,497
  • 18
  • 64
  • 109
  • 1
    What exactly does the back button do? history.go(-1)? if so, the backspace key already does this. Otherwise, simply bind a keypress event to the body and listen for the keys you want. – Kevin B Nov 20 '13 at 22:13
  • @KevinB Hi, thank you for the reply! You see, the back button in my app would point to a specific url. It would not be the last page viewed as would be applicable when you press backspace. Please provide laymen s terms on the alternate, my understanding of javascript/jquery is minimal to say the least. Any links would be appreciated!!! – Craig van Tonder Nov 20 '13 at 22:20
  • http://learn.jquery.com/events/ – Kevin B Nov 20 '13 at 22:20
  • Thanks a lot! I will take a look and give it a bash :) – Craig van Tonder Nov 20 '13 at 22:25
  • @KevinB There you go, take a look. Thank you so much!!! – Craig van Tonder Nov 20 '13 at 23:01

1 Answers1

2
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).keyup(function(e) { 
    if (e.keyCode == 27) {
        url = $("#backLink").attr("href"); // This would be the hyperlink href attribute
        window.location.replace(url); // url redirects to the new location
    }   // Trigger on esc keypress
});
</script>

Sources:

@KevinB the legend!

How to detect escape key press with JavaScript or jQuery?

Change URL and redirect using jQuery

Community
  • 1
  • 1
Craig van Tonder
  • 7,497
  • 18
  • 64
  • 109