Back button on pages with tabs - php

I'm doing a system where the pages are displayed by tabs (easytabs Plugin http://os.alfajango.com/easytabs/#tabs1-js)
At one point in the process it performs a query in the database, where we
see all the details of each item that appears. I'd like to go into the details of the item, click back to the (on broswer or a button) the page to return to the list displayed by the SQL query, just as with any single page, but currently it only displays a blank page.
I wonder how can I do to implement this solution using the layout tabs.
Thank you.

There are various ways to maintain UI state. One of them is using a "url hash". For example, you click tab 2, change the url hash to:
mypage.php#tab=2
Then if someone presses BACK and goes FORWARD, you use JavaScript to look at the URL has and determine that the user had previously pressed tab 2, so you run your own bit of code that triggers the same event.
I'm unfamiliar with "easytabs" so I'm sorry I can't help with the specific implementation details, but that's the gist of the technique.

Related

Modify back button behaviour in Laravel

Here is my scenario:
I have a number of list items such as this:
List item
When I click on the delete item, it goes to the controller, deletes the item from the database and redirects me back to my list of items.
When the user presses browser "Back" button, a request once again is made to "/item/1/delete", however, I would like them to go back to where they were before the accessed the list of items.
I am wondering if there is a best practice/laravel way of solving this, that said, any useful alternatives are welcome.
I would personally use
return redirect('home/dashboard');
This way you can ensure the suer will go back without posting the form.
Also you can add more things like a session message to pop up (i.e Profile Updated)
return redirect('home/dashboard')->withMessage(['msg', 'The Message']);
https://laravel.com/docs/5.5/responses#redirects

why is browser the back button not directing to the last viewed page?

I'm working on a site (reworking is probably a better word as I did not build it originally) and am encountering the following weird scenario:
Users go to a page which shows a list of current events. This is called "whats-on".
I have added a link to this page which takes users to a full event calendar for the month in a typical calendar format. This page is called "event-calendar". Once on the page they can also select which month they want to see and what type of events they are interested in.
Users can click on an event listed in any date to navigate to a page with the event details. (page is event-details with a query that pulls the relevant event.) I have added a back button to the page under the event listing which will return them to the calendar showing the month and search results they just looked at. No issues there - I am using PHP $_SERVER['HTTP_REFERER'] and that works perfectly.
Here is the issue - if I just did a back() or history.go(-1) link on that button, it takes the user all the way back to "whats-on". The same thing happens when you click the browser back button. It just skips over "event-calendar" entirely.
This apparently happens on the site under other scenarios such as business listings and searches.
Obviously I do not want that behavior - I want the back button to go to the previously viewed page like it should!!
I cannot think of anything in the code that would cause this, but the original site developers included a whole bunch of JQuery packages such as jQuery UI, and I'm wondering if something could be interfering with the default back button behavior. Is that even possible??
I guess what I want to know is there is any JQuery code that would change the behavior of the back button so I could hunt it down and kill it!!
Just looking for ideas as to where to start looking.
Apparently the only way I can get it to work is to manipulate the browser history using
history.pushState({}, '', 'event-calendar?<plus whatever query was used to pull the data>');
on the calendar page itself.
This seems to work but what a stupid workaround. Wish I could find the original problem.

page navigation in html

Hi i am tryng to implement a web application and i was wondering if html offers any page navigation techniques.
My query is Am going like this in my current page navigation,
Page A --> Page B --> Page C --> Page B
if i press back from this Page B position it will go to Page C, I dont want that to happen, instead, i want it to go to Page A.
The reason is that consider
Page A as login page
Page B as home page with some options, when clicked on any one it will go to Page C
Page C corresponding clicked function, say text boxes where i can input name, address etc, and when i fill and click on submit, it will go to page B.
Now if i press on back button from this Page B, i will be navigated to Page C. I dont want this to happen, i just want to stay in that page in this case.
but if the scenario was like this
A->B->C->D->C..
then on pressing back from last C i need to go to B, and if i press back from B, either stay on that page or prompt me to logout.
Hope my question is clear please dont down vote this, i want to learn, only these forums are there to help me
Please help
The browser-back-button belong to the user.
Its a "go back in history"-button.
so ... imo dont touch it.
provide a useful navigation so that user dont even think about using the back-button =)
There are two ways to do this as far as i am aware.
Personaly i would use JS to create a simple logon page, that opens a page containing an iframe, which is linked to your site. If the user hits back, it will take them to the logon page, as the site is contained within an iframe.
The other way is to change the propertys of the back button, rather than removing it with JS. I think this can be done with.history, but i have never used personaly so i dont know.
Hope this helps :)

Echo out text on previous page after link?

Basically i have a favorite icon on the users profile page. Another user can press this button and it will link to favorites.php where it will carry out the sql query to add that user to the database.
This then leaves the user stuck on favorites.php faced with a blank page. What i want favorites.php to do is after its processed the query is echo out a piece of text that says user added to favorites on the previous page profile.php. but i can't simply redirect them to profile.php using header because each user profile has an id extension like profile.php?id=13 and they will have clicked on that users profile.
so my question is can i use a header to redirect to the previous page they was on (url specific) so that its that users id they was originally onwith that corresponding . can this be done?
Thanks
This sort of UI interaction is typically accomplished with AJAX calls these days.
When the user clicks on the favorite icon, a bit of javascript on that page would call favorites.php in the background. Favorites.php would then issue the SQL call and return a bit of json (using json_encode()) to tell your Javascript code whether or not the SQL was successful. Your javascript would then react and update the UI accordingly.
jQuery is a very common way to accomplish this, so I'd suggest a quick google for "jquery ajax tutorial".
If you absolutely must support browsers which don't have javascript, the alternative would be for favorites.php to look at the referer:
<?php
//do important stuff here
http_redirect($_SERVER['HTTP_REFERER']);
?>
However, php's manual indicates that HTTP_REFERER is not reliable, so you still may end up with errors. Ajax for the win.

Simple question about javascript history.go

I have a classifieds website.
In every classified, there is a back link which simply takes the browser back one step.
This is because when users search classifieds, and click on one to view it, they can easily go back with a link also (instead of only the browser back button).
Here is the problem, if the classified is entered directly into the adress bar of a browser, or if somebody bookmarked a classified, then this back-link would take them someplace else...
Is there any way of making sure that the previous page is a certain page (index.php in my case)?
This way I would only display the back link if the previous page was index.php...
Thanks
You can't query history data. A slightly better option is to read the Referrer server variable and create your "Back" link to it. It's not very much stronger than history.go(), though. Try using a common index page instead.
Why not just insert a link to index.php directly? That way you have complete control over the target of the link. No need for JavaScript.
You should track their session within PHP or whatever language you're using in order to have an effective "back" button.
You could pull the data with document.referrer but that will not always give you the previous page. Sadly I am not sure of a way to achieve a "Back" button via javascript without using some kind of scripting language to track a user either via cookie or session.

Categories