Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 2878

Need some mechanism to prevent navigation via browser back

$
0
0

Hello All,

 

For an SAPUI5 application with hash based navigation, we need some mechanism to prevent browser back navigation. We couldn’t find any UI5 way of doing it so we tried using widows native events.

 

We tried to follow some of the following references:

:

 

https://jam4.sapjam.com/search/universal_search2?category=all&group_id=7MFgdXHJVVv2BWC8g0Ubep&query=browser+back

http://stackoverflow.com/questions/25806608/how-to-detect-browser-back-button-event-cross-browser

 

 

We tried using window.onhashchange and calling event.preventDefault().

 

With this, we could cancel the navigation but we could not avoid the hash from getting changed. So, it creates inconsistency between the hash in the URL and the page being displayed.

 

To handle this, we tried replacing the current URL with the old one using location.href=event.oldURL.

But we encountered 2 more problems with this workaround:

  1. The history is getting corrupted.
    1. Since the hash is getting changed, the history will have an entry with the new URL, which is not expected because we cancelled this navigation by calling preventDefault().
    2. It will have an extra entry with old URL because of location.href=event.oldURL code.
  2. oldURL attribute of the event object is not supported by all the browser (IE doesn’t support it).

 

 

Is there a proper UI5 way of handling this? If not, can someone please suggest a workaround to handle this?

 

Note: this is important for our application, because if not handled properly it can lead to data loss for the end user.

 

Thank you.

 

Regards,

Twinkle


Viewing all articles
Browse latest Browse all 2878

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>