Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to disable backspace "go back" navigation? #608

Closed
rfgamaral opened this issue Nov 16, 2014 · 11 comments
Closed

How to disable backspace "go back" navigation? #608

rfgamaral opened this issue Nov 16, 2014 · 11 comments

Comments

@rfgamaral
Copy link

Here's my attempt at this rfgamaral/SlackUI@6503fd7.

This prevents the browser "go back" navigation but also prevents the user from deleting characters from an input text box, which is not good. I can't seem to detect if the focus is on an input text box or the browser and disable the backspace key press accordingly.

What other options do I have?

@jankurianski
Copy link
Member

@rfgamaral It looks like this thread on upstream CEF forums may be relevant:
http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=10780

For CEF3 return true if navigation_type == NAVIGATION_BACK_FORWARD in CefRenderProcessHandler::OnBeforeNavigate.

@amaitland
Copy link
Member

CefRenderProcessHandler::OnBeforeNavigate is not currently implemented as it's in the Render process, so difficult to access, requires IPC.

I'd try IRequestHandler.OnBeforeBrowse, and look at IRequest.TransitionType, something like this

bool IRequestHandler.OnBeforeBrowse(IWebBrowser browser, IRequest request, bool isRedirect)
{
    if (request.TransitionType == TransitionType.ForwardBack)
    {
        return true;
    }
    return false;
}

@rfgamaral
Copy link
Author

There's no such thing as TransitionType in CefSharp v33.0.2 as far as I could tell... :(

EDIT: It seems it was only added at c92a26d.

EDIT 2: I compiled CefSharp from source and your idea seems to be working as expected. I just had to change the if statement to if(request.TransitionType == (TransitionType.Explicit | TransitionType.ForwardBack)) cause TransitionType is equal to Explicit | ForwardBack when the backspace key is pressed.

If this is an acceptable solution and the Explicit thing does not present a problem, please close the issue.

And thank you, once again :)

@jankurianski
Copy link
Member

@rfgamaral Perhaps this is because Explicit means the user did it via pressing Backspace. If JavaScript does history.back() will it be caught by your if?

This will cover all cases where ForwardBack is included in the flag:
if ((request.TransitionType & TransitionType.ForwardBack) != 0)

@rfgamaral
Copy link
Author

Not sure if my if will catch that but I'm only looking to prevent navigating back by pressing the backspace key, at least for now. I'll keep your second if in mind, in case I need it in the future :)

@amaitland
Copy link
Member

@rfgamaral Glad you found a solution, closing now.

@rfgamaral
Copy link
Author

I found an issue with this and I was not sure if I should have opened a new issue so I'm just posting it here.

It mostly works but I found a situation where it doesn't. When the browser is first opened within my SlackUI application, you have a form to login and a link to reset your password. If you open that reset link, you'll have a POST form to input your e-mail address and have a reset link emailed to you. After successfully submitting the form (inputting a valid e-mail address), you are presented with a "success message". On this screen, if you press the "Sign In" button at top-right of the screen (to load the log-in page) and follow that by pressing the backspace key, request.TransitionType will be equal to 16777223.

This means it will never be caught by (TransitionType.Explicit | TransitionType.ForwardBack). I could add an else statement for this value, but I have no idea what it means and if I should that.

@jankurianski
Copy link
Member

That is 0x01000007 in hex, which is the combination of ForwardBack = 0x01000000 and FormSubmit = 7.

To find this out, use Google to search 16777223 in hex, then compare this with the hex values in TransitionType.cs. Any hex value that starts 0x01... has ForwardBack.

@jankurianski
Copy link
Member

Also, if ((request.TransitionType & TransitionType.ForwardBack) != 0) would cover the combination of ForwardBack with any other flags.

@rfgamaral
Copy link
Author

I guess I'll have to use your solution after all :)

Thanks.

@amaitland
Copy link
Member

@rfgamaral Your welcome to go through cef_transition_type_t (cef_types.h) and make sure it maps correctly to TransitionType

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants