Welcome to WebmasterWorld Guest from 54.227.127.109

Forum Moderators: open

Message Too Old, No Replies

Javascript Gallery: Keyboard Shortcuts 'n' for next and 'b' for back

     
8:48 am on Aug 17, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 26, 2006
posts:1397
votes: 0


What's the simplest and shortest code that works in all major web browsers today esp. IE?
2:23 pm on Aug 18, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Feb 26, 2010
posts:74
votes: 0


function keypress(e){
var key_s = (window.event) ? event.keyCode : e.keyCode;
document.getElementById("entry").innerHTML=key_s;
}

this words. key_s will need to be incldued in your rules and decide your logic, but this works.
2:34 pm on Aug 18, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 26, 2006
posts:1397
votes: 0


Thanks.

So how would the code look if the next page is next.html and the back page is back.html
2:38 pm on Aug 18, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Feb 26, 2010
posts:74
votes: 0


do your homework. i'll check back tomorrow if you still haven't figured out.

look into "window.location"
6:42 am on Aug 19, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 26, 2006
posts:1397
votes: 0


Does that mean you don't know the answer?
2:16 pm on Aug 20, 2010 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts:5012
votes: 23


I think jason_m was simply trying to encourage you to learn. Like the old saying:
Give a man a fish and he will eat for a day. Teach a man to fish and he will eat for a lifetime.
In other words, it's often more beneficial for you to learn how something works than to simply give you something that does exactly what you need.

In this particular case, he gave you a hint (window.location). key_s contains the key that was pressed. So, if the key is 'n', you would do:
windows.location = http://example.com/next.html;
7:06 pm on Aug 23, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Feb 26, 2010
posts:74
votes: 0


potential,
no. i definitely knew the answer (Fotiman gave the solution).
in my experience, many coding issues (conditional on a generally okay [not even strong] base knowledge) is mostly an issue of not knowing what keyword to search on. i gave you a window into this.

unless you can construct conditionals, loops and other minor tricks you are pretty much out at sea. if i code it for you (which i could have, but chose not to) you don't learn anything and you possibly lose out on becoming an able coder.

in all honesty, when i answered your question (keypress) i googled then implemented in a sample page for you before posting my response. i put in a fair amount of effort to validate my answer to you. thought maybe you could put in that last step.

guess not ;)
7:50 pm on Aug 23, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Feb 26, 2010
posts:74
votes: 0


totally kicking myself right now but what am i possibly doing wrong here? i thought i had this working but for some dumb reason it is not firing: [note: tried in ie,ff,chr]

<html>
<head>
</head>

<body>
<textarea rows="20" cols="61" id="entry" name="entry" class="body_text" wrap="physical"></textarea>
</body>
</html>

<script>

function keypress(e){
var key_s = (window.event) ? event.keyCode : e.keyCode;
document.getElementById("entry").innerHTML=key_s;
}
</script>
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members