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

Use JavaScript for back links #494

Closed
joelanman opened this issue Mar 12, 2018 · 8 comments · Fixed by #1103
Closed

Use JavaScript for back links #494

joelanman opened this issue Mar 12, 2018 · 8 comments · Fixed by #1103
Assignees
Labels
Feature Request User requests a new feature 🕔 Hours A well understood issue which we expect to take less than a day to resolve.

Comments

@joelanman
Copy link
Contributor

We currently recommend people add URLs to back links by hand. I think in the large majority of cases, using JavaScript to go back will be fine, and means it Just Works, making prototyping easier and faster.

@timpaul
Copy link
Contributor

timpaul commented Mar 12, 2018

Just double-checking you mean just for prototyping - rather than for the back-link component in GOV.UK Frontend?

@joelanman
Copy link
Contributor Author

Yeah I meant just for prototyping, but you raise a good point, another example of where production and prototyping needs might be different. Maybe the kit can consume the back link, and add the JavaScript to it in the template question page

@NickColley
Copy link
Contributor

We should consider if the JavaScript should be used in production too.

@timpaul
Copy link
Contributor

timpaul commented Mar 13, 2018

Agreed, given that the browser back button should work as advertised anyway.

$$ question: What kind of 'back' is the right one? Is it whatever the previous page was, or some predetermined URL?

Example: You go back to question 5 from the 'Check your answers' page. Does the back link:

a) take you to the 'Check your answer' page
b) take you to question 4

@joelanman
Copy link
Contributor Author

I think it's the check your answers page, but probably some research would help. But I think the previous browser page (JavaScript history -1) is the majority case so it'd be useful to change that in the kit. It can always be changed for specific contexts.

@timpaul
Copy link
Contributor

timpaul commented May 20, 2019

Suggest we start by changing the link in breadcrumb on the Question page template to 'JavaScript history -1'

@timpaul timpaul added 🕔 Hours A well understood issue which we expect to take less than a day to resolve. Priority: low Feature Request User requests a new feature labels May 20, 2019
@NickColley
Copy link
Contributor

NickColley commented Jul 1, 2019

This came up again on support, this is the response I gave:

You can use window.history.back() in JavaScript to take users to the page they were previously on.

To do this with Nunjucks you can set the href option to javascript:window.history.back().

{{ govukBackLink({
  text: "Back",
  href: "javascript:window.history.back()"
}) }}

This approach is not appropriate for production scenarios, where you cannot rely on JavaScript being available at all times.

@chrisadesign
Copy link
Contributor

There was a conversation on Slack and Joe encourgaed us to share, so my two pence...

We're working a large prototype at the moment with a bunch of different designers, some of which use JS back links. It causes a bit of a problem in that links will be shared to page in the journey and you'll want to see what came before, but the back link doesn't work.

Not a massive problem but adding URLs makes the teams lives a lot easier.

One negative though is that we have to deal with pages, like CYA, that might have different routes to get to it, so we have to have some if statements to deal with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request User requests a new feature 🕔 Hours A well understood issue which we expect to take less than a day to resolve.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants