[Javascript/jQuery] On key press redirect to a new page ?

Status
Not open for further replies.

BlaZe

Active Member
Veteran
3,985
2009
767
505
I'm stuck on this. I have absolutely zero knowledge of jQuery/Javascript.

What I want to do is whenever a user presses spacebar, that page gets redirect to a new page.

For example, you are reading this thread and immediately you press F12 then this page should redirect to Google.

Keypress: A Javascript library for capturing input this is what I found for handling the keypress events.

If anyone can help :D
 
1 comment
I'm stuck on this. I have absolutely zero knowledge of jQuery/Javascript.

What I want to do is whenever a user presses spacebar, that page gets redirect to a new page.

For example, you are reading this thread and immediately you press F12 then this page should redirect to Google.

Keypress: A Javascript library for capturing input this is what I found for handling the keypress events.

If anyone can help :D


This is quite easy, just add this to your <body> tag:

Code:
onkeypress="window.location.href='http://www.google.com';"

So it'll look like this:

Code:
<body onkeypress="window.location.href='http://www.google.com';">


Press any key...


</body>

You can see it working here:
KeyPress Page Redirect
 
Status
Not open for further replies.
Back
Top