1

I try to listen if the user is pressing one of the buttons: Back, Start or Search (<- not available anymore) , on a Windows Phone, and simply output an alert if this is the case

e.g. alert("user pressed start");

Is this possible?

I'm trying to find out if the user is about to close the browser and execute a function before he does. On desktop browsers this is easily done with onbeforeunload, but this does not seem to work on mobile browsers.

Black
  • 18,150
  • 39
  • 158
  • 271

3 Answers3

2

Those are hardware buttons, handled by the OS, not your website, so no, You can't do that.

Rando Hinn
  • 1,255
  • 19
  • 41
  • Is there nothing like an API or some workaround which allows me to do this? Keyboard buttons on a normal computer are also hardware buttons, handled by the OS, so where is the problem? – Black Apr 12 '16 at 13:29
  • 1
    Not that I'm aware of, no. – Rando Hinn Apr 12 '16 at 13:31
2

Look at this answer: Bind to mobile device hardware buttons

Basically if you make an hybrid app with a framework such as Cordova Phonegap you can bind an event listeners to physical buttons.

Community
  • 1
  • 1
Gokhan Demirhan
  • 1,099
  • 10
  • 14
1

You can receive key events for the back button and the camera button.

as you see here : https://msdn.microsoft.com/library/windows/apps/jj207557 .

Some help: (How can i receive the hardware key button event On Windows phone 8?)

By the way, i think isn't worth the trouble. These keys are intended for exclusive use of the OS and you won't have any real benefit for your app by hacking that behaviour.

Community
  • 1
  • 1
fruggiero
  • 943
  • 12
  • 20