?
Solved

Indicate the link that was clicked when users clicks back button

Posted on 2013-01-29
7
Medium Priority
?
363 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

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

Industry Leaders: 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!

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

762 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