[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Indicate the link that was clicked when users clicks back button

Posted on 2013-01-29
7
Medium Priority
?
370 Views
Last Modified: 2013-02-04
Hello Experts!

I have a long list of contacts - clicking on a contact, takes the user to a page where they can view the contacts details. When the user clicks "return to list", I look up the value of a cookie to determine the last viewed contact and highlight them by applying a CSS class to that row of the list.

However, often the user will then click back button on the browser rather than my link.

Is there anyway we can get the record to be highlighted? I have tried setting the selected row via the following jquery:

		target = $.cookie("lasteml");
		$(".current").removeClass("current");
		$("#"+target).addClass("current");
		

Open in new window


However, this only reverts to the state the list was in when originally loaded, rather than showing the last clicked item.

I've also tried preventing default on the click, adding the highlight class and then redirecting the users - however again, when back is pressed, we return to the page in its original state.

Is there a way around this?

I would prefer not to disable cacheing if possible (but if that's the only way, I'll have to do it that way).

Thanks,
Dan
0
Comment
Question by:stressfreewebs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 38831973
However, often the user will then click back button on the browser rather than my link.
remove the history to prevent this :
http://stackoverflow.com/questions/7816195/how-to-disable-back-button-in-browser-when-user-logout-in-classic-asp
0
 

Author Comment

by:stressfreewebs
ID: 38834359
Hi Leakim,

We don't really want to disable functionality...but the lack of workarounds is making me think what we would like to achieve might not be possible without disabling caching so that the page is forced to reload.

Dan
0
 
LVL 11

Expert Comment

by:mcnute
ID: 38834747
Just to check and debug, try to print out the value of your cookie in the console like this:
target = $.cookie("lasteml");
console.log(target);

Open in new window


This will tell you if you're retreiving the right cookie value, or if the value is set correctly in the cookie.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Accepted Solution

by:
stressfreewebs earned 0 total points
ID: 38834823
Hi Mcnute,

We did print an alert and were able to deduce that we had the correct id.

I couldn't get it to work, so had to disable caching unfortunately, but this did at least get the highlight to work.

I added the following to the ASP code:

Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1

Open in new window


If anyone has any solutions which don't involve disabling cache I'd still be glad to hear them.
0
 
LVL 11

Assisted Solution

by:mcnute
mcnute earned 1500 total points
ID: 38834880
It is not totally possible to catch the back button event in all browswers as pointed out here. What you can do is to make a refresh on document onload, this will refresh the page once after the backbutton triggered the request once. This is considered a temporary workaround because this doubles your server traffic.

See this guy explanation why: http://www.irt.org/script/311.htm

Also see this for more information: http://stackoverflow.com/questions/6359327/detect-back-button-click-in-browser
0
 

Author Comment

by:stressfreewebs
ID: 38834884
Thanks mcNute,

That's cleared it up so I'll take my earlier solution as the best option for me here because disabling the cache server side will intervene to reload at an earlier point.

Thanks
0
 

Author Closing Comment

by:stressfreewebs
ID: 38850413
Most suitable solution
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question