cm2
cm2

Reputation: 195

:Visited Links Without Leaving page

I am building a Sharepoint page currently. The page uses anchor tags for links that instead of navigating away from the page, fire a modal dialog box. These are to function as if they are normal links. NOTE: the div contents are pulled in via rest meaning they are populated through javascript functions, so editing the css manually will not persist.

I am using the anchor tags because I want access to the :visited tag so users know which links they have viewed before. The issue here is that I had been using placeholder tags of href='#'. This does not give me the intended results, because when each link has href='#', visiting one link changes the color of all links on the page.

I attempted to include the link being opened through my Dialog box function so that each link would have a unique URL, but in order to avoid navigating away from the page, my function returns false, which in turn does not trigger the :visited event.

Is there any way for me to have unique URLs that will differentiate non-static Div entries with :visited subclasses without having the anchor navigate away from the current page?

<a class="hyper" href="myLinkHere" onclick="return myDialog(//start dialog then return false);">This is a Title</a>

Upvotes: 3

Views: 549

Answers (3)

Harsha
Harsha

Reputation: 11

@James Waddington: Your answer is superb !! You solved this issue with a small tweak. Now i can use visited links for modal box or color box too.

You can use #something in the href to specify an internal page id to link to. If you specify an id that's not on the page, you will have a unique ID that marks the link as visited, without actually taking you anywhere. e.g..

<a href="#test">Test</a>
<a href="#test2">Test</a>
<a href="#test3">Test</a>
<a href="#test4">Test</a>

Upvotes: 1

Brian Warshaw
Brian Warshaw

Reputation: 22984

If your intention is to preserve the link state in one session, then just manage it in javascript. Before you return false, alter the CSS class or do whatever else you'd planned to alter the appearance of the link.

If your intention is to preserve the link state across sessions, then use a combination of javascript on the client side and whatever you're using on the server side to maintain that state for a given user.

I know in some sense it would be easier to keep it all client side if you could, but let's face it--the user isn't actually visiting anything when they click on the link, and so it is not necessarily the most logical choice to try to act as though they are.

Upvotes: 2

James Waddington
James Waddington

Reputation: 2905

You can use #something in the href to specify an internal page id to link to. If you specify an id that's not on the page, you will have a unique ID that marks the link as visited, without actually taking you anywhere. e.g..

<a href="#test">Test</a>
<a href="#test2">Test</a>
<a href="#test3">Test</a>
<a href="#test4">Test</a>

Quick Fiddle.

Upvotes: 0

Related Questions