-2

I currently have this code snippet in a CGI script:

document.onkeydown = function(e) {
    switch (e.keyCode)  {
        case 37:
            document.location = "?direction=West";
            break;
        case 38:
            document.location = "?direction=North";
            break;
        case 39:
            document.location = "?direction=East";
            break;
        case 40:
            document.location = "?direction=South";
            break;
    }
};

That will update the QUERY_STRING and then reload the page. Can this be done without constantly reloading after every key stroke? JSON? jQuery?

I've tried fiddling with url.replace() and history.pushState().. no luck..

Sandeep Sukhija
  • 1,156
  • 16
  • 30
idavidgeo
  • 1
  • 2
  • 1
    This question is **way** too broad. A good direction would be start reading about jQuery and AJAX. – Koby Douek Nov 14 '17 at 07:17
  • This code will not reload after every keystroke. If that happens, there must be some other code as well. Also, `history.pushState()` should allow you to change the url without reloading the page. – GolezTrol Nov 14 '17 at 07:21

1 Answers1

0

you can use window.history.pushState('page1', 'Title', 'page1?direction=West'); for this. for more infomation adn help check link

A.D.
  • 2,352
  • 2
  • 15
  • 25