Multiple actions on click - ordering issue - hyperlink

When the user clicks on a link to a subpage, I want to store data in sessionStorage from the current page before leaving to the next page. Then when this new page has loaded, I want to apply the sessionStorage data on this page.
What complicates things is that the link is part a collapsing menu system. Which means that this system needs to update (which is also done on click) before the page data is stored.
So essentially, the wanted execution order:
User clicks link
Menu system is updated
Page data is stored
Browser loads the new page
Page data from the previous page loads and applies on the new page
My issue is the order in which everything is executed. I don't understand when the user clicks on the link how to control the order of when the actions are executed.
Thankful for help

Related

Handling the back button while using multi step remote links

I have a 3 step report which loads by clicking a link with the remote: :true option, so it reloads a part of the page instead of refreshing the whole page. I also provide the user with breadcrumbs, so he/she can easily navigate between the steps. However, most users use the browser back button, which of course reloads the whole page. What is the "Rails way" of dealing with this? If the browser back button is clicked the user should see the previous step in the report.
If you need to control the history the user sees, but aren't doing full page reloads on form submit, you should be manipulating the history state via Javascript's history.pushState and friends.
Assuming the responds to the submitted form is some sort of evaluated Javascript, simply include the history state manipulations there.

Ruby on Rails: Page Redirect Issue

I am having trouble with a page redirect issue in a small multi-step form process within a Rails application. Here's the rundown,
1.) There are 3 pages to this form with a, "save" and "next", button at the bottom of each page.
2.) If a user has filled out new information on the page, and attempts to click the next button, a warning modal popups and prompts the user to save their changes, or discard. This is where my issue is occurring.
3.) Instead of directing the user to the next page as they intended after pressing the modal save button, it instead just refreshes the same page the user is currently on.
I've tried everything, but honestly am not very experienced with Rails. I have made a collection on codepen for you to see all of the files.
Rails Files
Quick breakdown of the three files you will see.
1.) The saveModal is the popup that prompts for save or discard.
2.) Skills is just one of the 3 pages in the form. Any important info for you here would be at the top and bottom of the document I assume.
3.) The controller code where I think the redirect is happening is also there.

on clicking browser back button redirect to an action method in mvc

I am new to mvc application and i am using MVC 5 version.The scenario that i face now is like if i click browser back button on staying inside any webpage inside my application then login page should be shown instead of showing any cached page.
I added below code in global.asax to clear the cache.So after some time if cache is cleared and back button is clicked then expired page will be shown.
protected void Application_BeginRequest(){
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();
}
My intention is to show the Login action method at any point of time if browser back button is clicked with in the aplication.Please help me out guys..
According to me this should never be done.
The back button on browser is a client / user action and it has a specific behaviour. You should not try to change something like that.
But its all up to you if you want to do something that would be really bad according to user persceptive.
What you can do is use the unload event in JavaScript or jquery. This will not just let you know when back button is pressed but when anytime the page is navigated away.
I had used this when dealing with data entry form to confirm navigation away after user has entered data without saving.
The unload event is sent to the window element when the user navigates away from the page. This could mean one of many things. The user could have clicked on a link to leave the page, or typed in a new URL in the address bar. The forward and back buttons will trigger the event. Closing the browser window will cause the event to be triggered. Even a page reload will first create an unload event.
http://api.jquery.com/unload/
$( window ).unload(function() {
return "Handler for .unload() called.";
});
I think now you would be thinking of distinguishing what causes the unload event. But that is not possible, at least not in a cross browser way and without any hacks. You can refer this link for more details about it - Is there a way in javascript to detect if the unload event is caused via a refresh, the back button, or closing the browser?
update (copied from another SO answer):
Since you are doing this for logout-purposes you should probably use a timestamp variable at the server that gets updated with every request (or use a ajax-ping), and logout the user if it hasn't been seen for a specified time.

already logged page should be display when open new tab in struts2

I developing Struts2 project.
In that project the user can log in and do something its work fine.
If that user open the new tab and type my project url it will show the same page(after login page).
How do I implement the above scenario?
One way would be doing like described here, in a question almost identical to your (concept is the same, only the implementation, on .NET, differs).
Calculate an unique value each time you pass in the Action, then put
it in a session variable (that is server side) and use it to feed an
hidden field on the web page (that is client side).
When the page will post back (submit) the form containing your hidden field, you
will see if the page field and the session field are the same.
If yes: it is (the only OR) the last page / tab opened.
If no: you are trying to submit the form from a page that is not the
last page opened.
This way, you will always have only one instance of the web application, and if you open another instance of the web application in a new page / tab, it will invalidate the previous one: only the last opened will be valid (because of multiple hidden fields, one for each page, but only one session variable).
IF you really need (do you?) to prevent the user opening a new tab instead of ensuring a single instance for the web-app, start working from this principle and eventually come back here (better with some code)

ASP.NET MVC 3 - detect if dirty for multiple checkboxes on multiple pages

I'm using ASP.NET MVC 3.
I have a long list of items and I'd like to display them to the user with a checkbox next to each item representing whether the item is on or off. Because there are many items, the items are display using paging.
When a page is loaded, a checkbox is checked if the item is on. The user can page through the items, check/uncheck the checkboxes.
I want to enable the submit button only when there is a change of the items' states. What is the optimal way to detect if the list of items is in dirty state when the user pages through the list and makes changes.
How you would do this is different depending on if you are doing page refreshes for scrolling or ajax.
If you are just reloading the page with the new page information, then you will need some kind of state to keep track of the previously selected items. This could be done either in Session, or in a temporary table. A temporary table would survive a session reset, and would work in a server farm scenario.
In any event, either your page postsback on checkbox click, or you post on next page (In either case you want to do a post-redirect-get pattern). When the page refreshes, you need to return an indication of whether the collection is dirty or not, and enable the submit button.
Be aware that a user could walk away in mid-selection and come back half an hour later or something. If their login is still valid, and you use session, session may have recycled.
If you're doing Ajax, then you need to keep a running list of changes, so that if the user later unselects them you can disable the submit button again. You would keep this list in a hidden field, and either ajax post each checkbox as it happens to a temporary table, or you could just keep the running total in the hidden and apply the changes when submit is called. Your hidden field would probably contain a list of id's that you have changed (either checked or unchecked). And when the field is empty, disable the button and when it's not, enable it.

Resources