0
 Followers
2
 Likes

Back Button for Back in Browser History

Frontend
New

Sometimes we have to go back to a previous page.

We can do it in 3 ways:

1 - A button that has a specific link!

For example, I'm in a page with a List of Employees, and click in one of the Employees in the list, going to his Detail Page. There I have a button saying back that goes back to the list.

The problem of this solution is that If I can access the same page from a different place, when I click the back button I go to the Employee List Page and not to the page I was.


2 - A button that runs a Javascript!

I can have a button that runs the following javascript :

        window.history.back(); 

        return false;

This reproduce the back button web browser behavior.

The problem of this solution, are the Pop-Ups. If you open a Pop-Up in the page you are and run the javascript above, it goes back to the same page again. So in the end you stay in the same page.


3 - You can pass the Original URL as a parameter.

If you pass the Original URL as an input parameter of the next page you will access, you can always redirect the user to this URL again through a button or a link.


The idea is to make this a pattern!

OutSystems pages could always receive this Original URL input parameter behind the hood.

And could exist a component that would be a button or link that when clicked, redirects the User to this hidden URL.


This way we can always have the possibility to send the User back to the previous page!

Created on 12 Apr
Comments (8)

Changed the category to Frontend


Hi Raphael,

We already have such pattern in mobile, where you can navigate to a previous screen. Are you  talking about a similar approach for the web?

Regards,

Ricardo Alves

There's a server variable called HTTP_REFERER and it looks like you can access it from 

https://success.outsystems.com/Documentation/10/Reference/OutSystems_APIs/HTTPRequestHandler_API#GetReferrerURL



@Ricardo Alves, Yes it would be something similar.


@PJ M If I'm not mistaken, the referer URL dont work in the cenario you do a submit request for the same page.

It will work. In the case of a submit to the same page, the referrer will be the name of the page you are on. In other words, if a page submits to itself, then the referrer will be itself.

@PJ M   Exactly. This is what can't happen.  The purpose of the idea is to go back to the previous page that is not itself. It is the same problem of the case 2 in idea.

@Raphael, You've made a change to your requirements then, because if you can't go back to the previous page, then your suggested option of #2 wouldn't work either.

To do what you want, you'd have to store the referrer, then only go back to one that isn't the same page.

@PJ M... Yes the options 1 and 2 don't work! 

I just wrote them, because they usually are used, but they will not work. 

This is why I put in the end of them that a problem exist.

The only solution I see is what I wrote in option 3!
This is the idea!

views
553
Followers
0