Skip to content
WJunction - Webmaster Forum

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

Status
Not open for further replies.

BlaZe

Distinguished Member
Veteran
3,985
2009
767
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.

About the author

BlaZe
Distinguished Member · Joined
3,985
Messages
767
Reactions
113
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom