Porco
Porco

Reputation: 4203

How to get Ajax links marked as "visited" without messing up IE9

I have a page full of links that each AJAX in an article based off an ID. I'm trying to use history.pushstate to mark articles as "visited".

What I've done:

I added a hash to each link with the ID of the article:

<a href="#ID=123" onclick="ajaxLoad('123')">Title</a>

Inside my JS function I have something like:

if (window.history && window.history.pushState)
{
    window.history.pushState({articleID:"123"}, "Title",  "#ID=123");
} 

The value inside my href is not used in anyway, I just put it there so that the links would get "visited" CSS. This works well in most browser except of course IE9. Since IE9 does not support window.history, I never expected it to work.

However, my problem is that clicking articles in IE changes the URL to append the hashes on them and this pollutes the history (now have to click back a whole bunch of times to go back).

I know that I could get rid of the hashes and still have back button work (outside of IE), but I'm actually more interested in making sure my links get marked as "visited". Is there anyway to get ajaxy links marked as "visited" without having IE9 behavior compromised?

Upvotes: 0

Views: 494

Answers (2)

Neil
Neil

Reputation: 55392

Try adding this to your onclick handler:

if (event.preventDefault) event.preventDefault(); else event.returnValue = false;

Upvotes: 3

Neil
Neil

Reputation: 55392

Simply return false; from your onclick handler.

Upvotes: 0

Related Questions