View Full Version : search engine visited link issue

06-03-2009, 07:25 PM
I'm making a search engine type page using JSP w/ JSF. The visited links weren't working so I coded around it:

<title>Potential Solution to Linked List Issue!</title>
<style type="text/css">

//link style before click, shows when loaded
a.beforeclick:link {color:#0000FF;font-size: 12pt;text-decoration:underline;font-weight:normal}
a.beforeclick:active {color:#FF0000;font-size: 12pt;text-decoration:underline;font-weight:normal}
a.beforeclick:visited {color:#FF0000;font-size: 12pt;text-decoration:underline;font-weight:normal}
a.beforeclick:hover {color:#FF0000;font-size: 12pt;text-decoration:underline;font-weight:normal}

//link style after click (switch by onclick becoming true)
a.afterclick:link {color:#FF0000;font-size: 12pt;text-decoration:underline;font-weight:normal}
a.afterclick:active {color:#FF0000;font-size: 12pt;text-decoration:underline;font-weight:normal}
a.afterclick:visited{color:#FF0000;font-size: 12pt;text-decoration:underline;font-weight:normal}
a.afterclick:hover {color:#FF0000;font-size: 12pt;text-decoration:underline;font-weight:normal}

//these classes when coded will show red when hovered over, visited or active
//red will allow customers to skip or go back to previously viewed items more easily

//Start Javascript popup
<script type="text/javascript">

function launchPDF(PDFID){
alert("Would launch PDF # " + PDFID + " here");
//end script

//start html body
//here we set our link to launch the javascript box when
//clicked then change the link to a afterclick when onclick is true
<p><a href="javascript:launchPDF(12345)" onclick="this.className='afterclick';" class="beforeclick">Launch PDF 12345</a></p>
<p><a href="javascript:launchPDF(34567)" onclick="this.className='afterclick';" class="beforeclick">Launch PDF 34567</a></p>
<p><a href="javascript:launchPDF(56789)" onclick="this.className='afterclick';" class="beforeclick">Launch PDF 56789</a></p>
<p><a href="javascript:launchPDF(99999)" onclick="this.className='afterclick';" class="beforeclick">Launch PDF 99999</a></p>

Of course I will have many more links that will be coded by the search itself, so my question is how can I generally apply the onclick() switch link class to all links without hard-coding it?

Will Cipolli

Old Pedant
06-04-2009, 12:24 AM
function fixlinks( )
var links = document.getElementsByTagName("a");
for ( var i = 0; i < links.length; ++i )
var link = links[0];
link.className = "beforeclick";
link.onclick = function() { this.className="afterclick"; return true; }
window.onload = fixLinks( );

I think.

You sure you want to do this to *ALL* <a> tags???

You could inspect the href or the innerHTML to make the additions conditional, if that would help.

06-05-2009, 05:17 PM
The guys I'm working with set up a .css style sheet where they define all the links a:visited,link,hover,active.

Here is how the links are defined:

a:link, a:visited, a:active {color:#0000FF;}
a:hover {color:#FF0000;}

Here is where the PDF link is output on the screen:

<hx:outputLinkEx styleClass="outputLinkEx" id="formPdfLink"
onclick="return openPDFWord(this, '#{varsearchResults.targetURLForPDF}');"
<h:outputText styleClass="outputText" id="text7"
value="#{varsearchResults.formIdAndEditionDate}" escape="false"></h:outputText>

What I'd like to do is use onclick to just make the pdf links the search engine dynamically prints change color to red when onclick event occurs

I tried a couple times but have trouble getting it to work not too familiar with the web part unfortunately.


06-05-2009, 06:30 PM
Here was my attempt, which did not work. It just opened the PDF in the same window instead of a new one. Unfortunately I cannot reload the search screen, because of the nature of JSF/JSP, to see if the onlick worked.

<hx:outputLinkEx styleClass="outputLinkEx" id="formPdfLink"
onclick="return openPDFWord(this, '#{varsearchResults.targetURLForPDF}');" onclick="this.className='afterclick';"
<h:outputText styleClass="outputText" id="text7"
value="#{varsearchResults.formIdAndEditionDate}" escape="false"></h:outputText>

a:link, a:visited, a:active {color:#52658C;}
a:hover {color:#CC0000;}

//link style after click (switch by onclick becoming true)
a.afterclick:link {color:#FF0000;}
a.afterclick:active {color:#FF0000;}
a.afterclick:hover {color:#FF0000;}