如何获取键盘上的箭头键以触发博客中的导航(上一页/下一页)链接 [英] how to get the arrow keys on the keyboard to trigger navigation (previous/next page) links within a blog

查看:114
本文介绍了如何获取键盘上的箭头键以触发博客中的导航(上一页/下一页)链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止我拼凑在一起的脚本如下所示:

the script i've pieced together so far looks like this:

<script type="text/javascript">
/* KEYNAV */
document.onkeydown = function(e) {
if (! e) var e = window.event;
var code = e.charCode ? e.charCode : e.keyCode;
if (! e.shiftKey && ! e.ctrlKey && ! e.altKey && ! e.metaKey) {
if (code == Event.KEY_LEFT) {
if ($('previous_page_link')) location.href = $('previous_page_link').href;
} else if (code == Event.KEY_RIGHT) {
if ($('next_page_link')) location.href = $('next_page_link').href;}
}
}); 
</script>

我的html如下所示:

and my html looks like this:

<p>
{block:PreviousPage}
<a id="previous_page_link" href="{PreviousPage}">PREVIOUS PAGE</a> 
{/block:PreviousPage}

{block:NextPage}
<a id="next_page_link" href="{NextPage}">NEXT PAGE</a>
{/block:NextPage}
</p>

{PreviousPage} / {NextPage}代码表示不同的动态页面链接,具体取决于您所在的页面在...上。这个特殊问题特定于tumblr,但通常也是如此:

the {PreviousPage} / {NextPage} code represents dynamic page links which are different depending on which page you are on. this particular question is specific to tumblr, but generally as well:

有没有办法让我的左右箭头键触发这些动态链接?

is there a way to get my left and right arrow keys to trigger these dynamic links?

感谢您的阅读,非常感谢您提供的任何帮助。

thank you for reading and any help with this is greatly appreciated.

推荐答案

function leftArrowPressed() {
   // Your stuff here
}

function rightArrowPressed() {
   // Your stuff here
}

document.onkeydown = function(evt) {
    evt = evt || window.event;
    switch (evt.keyCode) {
        case 37:
            leftArrowPressed();
            break;
        case 39:
            rightArrowPressed();
            break;
    }
};

这篇关于如何获取键盘上的箭头键以触发博客中的导航(上一页/下一页)链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆