Browser Back Button Handling in Ajax Based Application - ajax

Similar questions have been asked on SO, but I am still looking for a solution and not a workaround.
I am working on an Ajax based application and when the user clicks on the Browser Back Button it takes the user to the login page(every page after the login page is ajax loaded). Apparently, this is not what the user expected.
We recommended using Bread Crumbs to the client
*Page One >> Page Two >> Page Three*
but the client insists that they prefer to use the Browser Back Button. Is there a way where it is possible to somehow embed the Bread Crumb links to the Browser Cache...in other words, clicking the back button invokes the same actions which clicking the Bread Crumb links would?
Regards,
SB

You could use the RSH (reallysimplehistory) javascript library: http://code.google.com/p/reallysimplehistory/

Related

how to create middleware in laravel

I have created the project which has login page login.blade.php which has only Regno to login-in.
once it login is the success it will redirect to home.blade.php and it followed by 4 more pages when clicking of next button in each page
page2.blade.php,page3.blade.php,page4.blade.php,page5.blade.php and finally, it should redirect to login page itself. The problem is the browser back button should not allow it to go back to the previous page.
can anyone suggest me how to create middleware for this?
thank you.
The browser's back button is not controlled by the server, where Laravel runs. There is no way for you to block it or interact with it in any way inside your PHP code.
What you can do is send XMLHHTTPRequest (XHR) with JavaScript. They ensure that on a button click you will stay on the same page in the browser and then your JS-code can read the server response (your rendered page templates) and replace the current content with the one from that response. You can read more on this when you google for AJAX, e.g. this article: https://www.sitepoint.com/use-jquerys-ajax-function/
Read this thing. I once implemented in the same way. By setting cache control in response header.
https://stackoverflow.com/a/51821808/10239067

MVC Ajax form and browser back button

I am currently working on an MVC site which has a search page that sits behind a login page. When the user logs in, they are redirected to the search page.
The search form uses an ajax form that returns search results to the same view.
When we have search results, the search form is no longer shown. This all works fine.
However, once you have fired off the form and have search results - the user will probably try and hit the browser back button to try and get back to the search form. Of course, this instead takes them to the previous page (the login page).
So, my question is this - I would still like to keep the form and results on the same page using ajax. Is there anyway that I can achieve this, in conjunction with when the user clicks back, it takes them to the search form?
I appreciate I am probably asking for too much here, but I thought I'd put it out there anyway!
ps - I already have a 'back to search' link which re-loads the form. I believe the average user will try and click the browser back button. I would also rather not have some sort of function on the login page that redirects them back to the search page.
You need to use the History API. It's supported in modern browsers, and there's a polyfill for IE9 and below.
UPDATE
For what it's worth, I agree with #TravisJ. This is a bad design, but if you insist on going down this path, then my notes above apply.

Zend Framework - creating a smart back button

I would like to have a button that depending on where the user was on the site, it calls the appropriate controller and action.
I have a page with a back button.
People can arrive on that page trough:
a) link on the homepage.
OR
b) trough a link on another page (inside the same site).
If the user comes from the homepage, the back button should point to that controller and action.
If, however, the user comes from that other page, the back button should point to another controller and action.
How can we accomplish something like this?
Thanks a lot,
MEM
ps - History Back is of no use, because we cannot allow that button to link to an external site.
Well, if you can't use javascript to go back in the history, then you have an undefined case when some external site leads directly to the page. Let's assume that if the user arrived at the page via an external site, the back button should simply not appear.
Consider checking the $_SERVER['HTTP_REFERER'] and constructing the back button link based on that. Inspect the referer (parse_url() may be of particular service here), if it's not your domain, don't display the button, otherwise, pick someplace to send the user "back" to (probably just the whole referer URL).

JSF and browser back

I have a very strict requirement to use POST to pass in request parameters to my application upon entry. Once entering the application (page1), entering form information and continuing to the next page (page2) via a commandButton, the expectation is that the data will be posted and later read from a session scoped manage bean. All works well except when using browser back on page2 to navigate back to page1.
I have tried adding a redirect tag on the navigation rule that navigates from page1 to page2 to no avail. I have also tried this implementation of the Post-Get-Redirect pattern (http://balusc.blogspot.com/2007/03/post-redirect-get-pattern.html). Am I missing something obvious here?
Abel, the scope of page1 is request.
The solution we came up with which is no means ideal is to disable browser caching on the previous page. What this means is that whenever you refresh the page using the browser refresh button or click the browser back button, the browser will indicate that the page is expired and prompt a warning asking whether you want to re-submit the request.
We do have a work around which is to provide navigation buttons within the webpage but the idea was to support browser back. This would be easy using GET parameters, but POST provides additional complexity which we have decided to mitigate by by providing our in-house navigation buttons.

Web page expired message in browser

I am implementing a web application using ASP .Net and C#. One of the pages has a requirement that it always needs to be fetched from the server, rather than from the local browser cache. I have been able to achieve this.
We have a back button in the application, which simply invokes javascript:history.back() method. The problem is that when the back button is clicked to navigate to the page which is always to be reloaded from the server, the browser displays a "Web page expired message".
The intent here is to force the browser to reload the page rather than display the web page expired message.
Any help would be highly appreciated. Thanks a ton in advance.
You will probably need to change the implementation to make the browser load the URL explicitly:
window.location.href = 'http://....';
instead of invoking the back button, since the intention of the back button is to get the last page from the cache.
(If browsers would not act that way, they would re-send your form data multiple times when using the back button during a registration process or similar.)
You mean you want to control browser behaviour, which is not possible. I doubt you can solve it that way. You could set the expiration time to a small value (1 minute perhaps?) so that the page is still valid if one navigates back quickly.

Resources