Solved

Indicate the link that was clicked when users clicks back button

Posted on 2013-01-29
7
350 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
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!

 

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 500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 …
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

733 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