amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

Proper `goback` functionality in AMP

Open keepitsimple opened this issue 10 years ago • 43 comments

UPDATE [May 14 2020] I'm pretty sure that the AMP team will spent another 5 years on decision "TO DO vs NOT TO DO". The workaround is simple - use iframe with JS code inside which calls history.back. Yes it's ugly but it works.


Can you please add some param for <button> or <a> tags which will do javascript:window.history.back() call?

I use amp-iframe as workaround for this issue, but it will be much more convenient to have dedicated "amp-" tag for it or an attribute for <button> or <a> tags.

Thank you in advance

keepitsimple avatar Sep 26 '16 14:09 keepitsimple

@ericlindley-g lets start a discussion on this here. This seems like a valid request.

camelburrito avatar Sep 26 '16 17:09 camelburrito

We could use the validator to whitelist a very specific javascript: URL for some href values.

Gregable avatar Sep 26 '16 17:09 Gregable

I agree that this seems like a valid request—is there any risk of abuse here? Can we define the validation narrowly enough that it would strictly allow only forward and back navigation?

Also, I'm assuming that in the viewer context this just behaves exactly as the back button would, dismissing the viewer. (?)

ericlindley-g avatar Sep 26 '16 22:09 ericlindley-g

All, this sounds like a very legitimate request but with some nuances.

@Gregable, I think we'll just continue using our on actions. Something like <a on="tap:history.back">.

@ericlindley-g, I'd like to hear more on this. But I'd ideally like to avoid going over viewer/document boundary. I.e. ideally I'd see this action going back in history for the document only: close lightbox, back to top, etc.

dvoytenko avatar Sep 28 '16 16:09 dvoytenko

@dvoytenko That makes a lot of sense—on reflection, it seems like the use-cases for an additional UI element in the document itself that navigates history back would only make sense within the context of that document, anyway, and not have particular need to close the viewer.

ericlindley-g avatar Sep 29 '16 16:09 ericlindley-g

Sounds good, in this case, I suggest the format be:

<a on="tap:AMP.goBack">

dvoytenko avatar Sep 30 '16 20:09 dvoytenko

Ping :)

keepitsimple avatar Oct 31 '16 16:10 keepitsimple

@ericlindley-g Let's schedule it soon?

dvoytenko avatar Nov 02 '16 19:11 dvoytenko

@dvoytenko Will do — we can schedule w/r/t the bandwidth of core AMP contributors.

And to developers in the broader AMP community—this might be a straightforward enough feature to be a good starter contribution :)

ericlindley-g avatar Nov 14 '16 18:11 ericlindley-g

@dvoytenko I checked in the releases. And it looks like the feature must be available by default. But it doesn't work for me. But in the same time it path through validation <button class="btn btn-default circle nob" on="tap:AMP.goBack"><span class="domicon domicon-arrow-long-left t5"></span></button>

keepitsimple avatar Jan 19 '17 20:01 keepitsimple

@keepitsimple Can you open another issue with a page that reproduces?

jridgewell avatar Jan 19 '17 20:01 jridgewell

@keepitsimple This should be released now everywhere. Please just ping the reproducing URL here and I'll take a look. As we discussed, at this time the navigation back is only done in the history stack of the document itself, not outside it.

dvoytenko avatar Jan 24 '17 19:01 dvoytenko

@dvoytenko Here you are: http://m.domino.com/main/issue1 Please click on the link on the page; then click a back icon.

keepitsimple avatar Feb 07 '17 16:02 keepitsimple

@keepitsimple I see. You actually want to back button to navigate between different pages. The current implementation stays within the boundary of each document. This is what I meant by:

But I'd ideally like to avoid going over viewer/document boundary. I.e. ideally I'd see this action going back in history for the document only: close lightbox, back to top, etc.

I'll check on what security measures we need to go across the boundary of multiple documents.

dvoytenko avatar Feb 08 '17 20:02 dvoytenko

I scheduled this for a wide audience for this week's design review (#7380). Please join if you can.

dvoytenko avatar Feb 14 '17 00:02 dvoytenko

Based on yesterday's Design Review (#7380), some feedback from participants:

  1. It appears that the ask is to allow back-nav outside of the context of the current document. This is likely a separate API from AMP.goBack.
  2. This has challenges with embedding AMP docs, which includes: a. The behavior of this button would differ for depending on whether back-nav is possible. E.g. with no history stack, this will be a non-functional UI. b. The parent app could be forced to close AMP viewer.
  3. One option is to disallow back navigation when the document is embedded. This is undesirable as it would show a non-function UI.

Couple of solutions proposed instead:

  1. A self-replacing navigation: <a data-replace=true href="./...">. Instead of using history.back, we'd purge intermediate history stack and replace the current page with the provided URL.
  2. Look into more sophisticated flows, including form submits to come up with back API, e.g. involving directing query params.

Any feedback on this feedback?

dvoytenko avatar Feb 17 '17 01:02 dvoytenko

Are we going forward on this? I feel like having the browser back button action is really helpful.

vamshi5889 avatar Jul 10 '18 10:07 vamshi5889

Do we still have no meaningful way to go back to the previous page? The concern with point 2.b in the feedback of the feedback is how browsers currently function. So a normal user, hitting the back button like a crazy person, would get to the home/empty tab screen regardless if they were using an amp button to tap or their phone or their mouse.

From a UX standpoint, it is quite fundamental to give us the ability to add a back button without having to break validation by adding JS or using work-arounds like iframe or force developers into custom-database tables to keep track of user movements just so they could use XHR posts to their API's to redirect users effectively.

Would love some movement on this topic because I feel if we can't get basic UX functionality (including navigation users are used to seeing on mobile designs by now), it just makes adoption of this technology superficial to the point where watered-down AMP pages are used just because google search gives them more preference in rankings, which really craps all over the UX (I've seen it with quite a few implementations on the web currently)

Hope @aghassemi doesn't think I'm being too aggressive with my post :)

AcidRaZor avatar Nov 21 '18 08:11 AcidRaZor

Hi @AcidRaZor We have AMP.goBack action already supported. It works with both normal navigations and amp-bind's AMP.pushState(). Sorry for not updating this ticket when that feature was added.

aghassemi avatar Nov 22 '18 01:11 aghassemi

Closing the issue as AMP.goBack action has been already implemented.

aghassemi avatar Nov 22 '18 01:11 aghassemi