I have a simple script that uses left and right arrows to move to next and previous blogpost.
var nextEl = document.getElementById("pagination__next__link");
var prevEl = document.getElementById("pagination__prev__link");
document.onkeyup = function(e) {
if (nextEl !== null) {
if (e.keyCode === 37) {
window.location.href = nextEl.getAttribute('href');
}
}
if (prevEl !== null) {
if (e.keyCode === 39) {
window.location.href = prevEl.getAttribute('href');
}
}
return false;
};
But it also works when I have text input
or textarea
focused. What would be the best way to disable the keyboard shortcuts when focused?
Thanks!
nextEl.onkeyup = prevEl.onkeyup = function(e) {...}
i can't really get it work... Have to listen to the document. – Bischoff