How can I prevent navigation back for the SPA application

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

How can I prevent navigation back for the SPA application

Postby iamarsey » Wed Sep 02, 2015 4:17 am

Hi, I use CEFSharp with single page application and trying to prevent a user to navigate back.
The solution "For CEF3 return true if navigation_type == NAVIGATION_BACK_FORWARD in CefRenderProcessHandler::OnBeforeNavigate." works corretly only for the pages that reloaded by the server, for SPA the method is not invoked when you click "backspace".
You can easily check it trying to prevent navigation for this site https://docs.angularjs.org/error/$animate/nocb between the links in the right menu
Any solutions?
iamarsey
Newbie
 
Posts: 5
Joined: Wed Sep 02, 2015 3:24 am

Re: How can I prevent navigation back for the SPA applicatio

Postby HarmlessDave » Wed Sep 02, 2015 12:39 pm

So there are no page or frame navigations, only dynamic re-writing of the page?

If text entry is not needed you could try trapping and discarding backspace key presses.

If the domain is fixed you could try a custom scheme handler for HTTP / HTTPS so you can snoop on the page update requests and cancel the backspace one. This assumes there is a CGI or JSON variable in the request that tells you it is a navigate back.

If backspace is mapped to a function in the page's scripts, you could modify that function either on the server or in the client after the page has loaded.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: How can I prevent navigation back for the SPA applicatio

Postby iamarsey » Thu Sep 03, 2015 3:11 am

I not exactly understand your suggestion: if you will try to move between the pages in the website I mentioned you see that url is changed as well as the content of the page.

I can`t prevent just one button click because the user can use other buttons, for example, additional mouse buttons or toolbar of the keyboard, so the solution have to prevent the functionality at all, not one exact button.
iamarsey
Newbie
 
Posts: 5
Joined: Wed Sep 02, 2015 3:24 am

Re: How can I prevent navigation back for the SPA applicatio

Postby HarmlessDave » Thu Sep 03, 2015 4:22 pm

So you are getting navigation events in OnBeforeNavigate, it is just that the NAVIGATION_BACK_FORWARD flag is not set?

For that case, you need to look at the URL string, and possibly at any POST data in the request.

The URL or request might include a CGI variable that tells you the movement is back, or the page address might tell you. If there is nothing at all in the request that you can use, do you need to allow any navigations at all?
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: How can I prevent navigation back for the SPA applicatio

Postby iamarsey » Fri Sep 04, 2015 4:31 am

No, I do not get OnBeforeNavigate event at all, the pages at the site I mentioned change without invoking that event because there is no request to the server, just the url is changed

Yes, I need to allow the navigation because the site I use is based on AngularJS and the rendered page is loaded as reaction to changing url that is changed when the user goes to other page.
iamarsey
Newbie
 
Posts: 5
Joined: Wed Sep 02, 2015 3:24 am

Re: How can I prevent navigation back for the SPA applicatio

Postby magreenblatt » Fri Sep 04, 2015 6:30 am

If it doesn't actually trigger a navigation then you can't block it.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How can I prevent navigation back for the SPA applicatio

Postby iamarsey » Fri Sep 04, 2015 6:38 am

Is CEFSharp I can subscribe the method
browser.NavStateChanged += OnBrowserNavStateChanged;
It have some arguments: object sender and NavStateChangedEventArgs args but I cant receive the necessary information about back action.
May be you have some ideas?
iamarsey
Newbie
 
Posts: 5
Joined: Wed Sep 02, 2015 3:24 am

Re: How can I prevent navigation back for the SPA applicatio

Postby amaitland » Fri Sep 04, 2015 6:54 am

`NavStateChanged` = `OnLoadingStateChange` in `CEF` terms. Unfortunately there isn't much information provided in that handler.

apidocs3/projects/%28default%29/CefLoadHandler.html#OnLoadingStateChange%28CefRefPtr%3CCefBrowser%3E,bool,bool,bool%29
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1292
Joined: Wed Jan 14, 2015 2:35 am

Re: How can I prevent navigation back for the SPA applicatio

Postby iamarsey » Tue Sep 08, 2015 10:01 am

Guys, this functionality is very crucial for me, do mean is noway to prevent back event for SPA application?
iamarsey
Newbie
 
Posts: 5
Joined: Wed Sep 02, 2015 3:24 am

Re: How can I prevent navigation back for the SPA applicatio

Postby HarmlessDave » Thu Sep 10, 2015 2:12 pm

If there are no navigation events, look into my earlier suggestion:

you could try a custom scheme handler for HTTP / HTTPS so you can snoop on the page update requests and cancel the backspace one. This assumes there is a CGI or JSON variable in the request that tells you it is a navigate back.


Or possibly use the ClientHandler::OnBeforeResourceLoad event and look at the request there.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 97 guests