Solved

Indicate the link that was clicked when users clicks back button

Posted on 2013-01-29
7
317 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
  • 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…

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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now