47
Views
7
Comments
Navigating out of Url
Question

Hello Community,

I have one scenario to take care.

When somebody navigates out of application via entering some other URL or hitting bookmarks, I want to show a Outsystems popup with yes and no

If yes, i will allow navigation and if no, then stay at same page.

e.g:-

I am at some URL1, I type URL2 in address bar and hit enter, i expect that popup.

2021-04-09 11-42-43
assif_tiger
 
MVP

Hi,
You can use the window.onbeforeunload function under the layout/page.. . & invoke your respective action.


Ref Sample :
https://code-maven.com/prevent-leaving-the-page-using-plain-javascript


Good Luck

2021-07-14 10-21-07
Krunal Vyas

Hello Asif,

Thanks for the solution, But this solution brings the browser default popup of leaving the site.

My req is calling outsystems popup.

Can you please help weather i can achieve that?

Thanks,

Krunal

2021-04-09 11-42-43
assif_tiger
 
MVP

- You can remove the return from the snippet
- Keep the Popup in the layout & let's say a hidden element[ can be button]; onclick of the element should call the popup... similar to what we do normally with Outsystems
- Now in the JS Snippet function; you just need to call the onClick of that element

2021-07-14 10-21-07
Krunal Vyas

Hello Assif,

I called my client action in the javascript

But without return it does not call the action and navigates out
or i can say that it does not stop navigation


Thanks,

Krunal

2021-04-09 11-42-43
assif_tiger
 
MVP

Hi,
Yes :(
- I gave a try with the same & yes... when we use return it works fine i.e it holds the navigation

- And if we remove return & call button-click or a click with return itself.. which is an OS popup in our case.. the popup render but the navigation is triggered

2021-04-09 11-42-43
assif_tiger
 
MVP

- Also going with the default Alert ... has a limitation; you cannot use the custom message.
  Most of the browsers will ignore the actual message and just show their own. 

2021-07-14 10-21-07
Krunal Vyas

Yes assif

We are facing that challenge

We want to build a pleasant UI experience for this behavior but not able to.


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.