Skip to content
Advertisement

How to perform own action on F5 key press in UI5?

I don’t know how to replace the F5 key action in SAPUI5.

I have a button “Refresh” which is reloading my business data in the UI and made some kind of manipulation before showing it on the view. I want to catch the F5-press so that my method to refresh can be called.

Advertisement

Answer

Just add an event listener to the window and call preventDefault() to stop it from doing the default thing of reloading.

(After running, click inside the white section to see it working. Otherwise the page will reload)

window.addEventListener("keydown", (event) => {
  if (event.key == "F5") event.preventDefault();
});
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement