• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 373
  • Last Modified:

Indicate the link that was clicked when users clicks back button

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
stressfreewebs
Asked:
stressfreewebs
  • 4
  • 2
2 Solutions
 
leakim971PluritechnicianCommented:
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
 
stressfreewebsAuthor Commented:
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
 
mcnuteCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
stressfreewebsAuthor Commented:
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
 
mcnuteCommented:
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
 
stressfreewebsAuthor Commented:
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
 
stressfreewebsAuthor Commented:
Most suitable solution
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now