Search code examples
javascriptwordpressfrontendsmart-tv-alliance

Change page on TV browser with channel changer button on remote control?


I'm trying to create a website and it's going to be used on Smart TV browsers...
I would like to facilitate user's navigation only using the channel changer button, so my question is:

Is it possible to make a function to detect Channel Up or Channel Down on my website and switch the page?

For example:
If I click on the Channel Up button on the remote control, it goes to page 2.
And if I click the Channel Down button on the remote control, it returns to page 1.

Thanks!


Solution

  • First thing to check: Is your TV sending the "key" press? You can use simple JS+HTML

    <!DOCTYPE html>
    <html>
    <body>
    <script>
    document.addEventListener("keydown", function(event) {
      document.getElementById("x").innerHTML=event.which;
    });
    </script>
    <p id="x">The keycode will appear here...</p>
    </body>
    </html>
    

    Then write down the keycodes. If they aren't showing up, bad luck. Your TV isn't sending the keypress. If they are, using simple "if" you can navigate with Javascript.