Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2009
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    search engine visited link issue

    I'm making a search engine type page using JSP w/ JSF. The visited links weren't working so I coded around it:

    Code:
    <html>
    <head>
    <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 
    </style>
    <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
    </script>
    </head>
    <body>
    <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>	
    </body>
    </html>
    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?

    Regards,
    Will Cipolli
    Last edited by wcipolli; 06-03-2009 at 06:51 PM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Code:
    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.

  • #3
    New Coder
    Join Date
    Jun 2009
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    After some investigating

    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:

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

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

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

    Regards
    Last edited by wcipolli; 06-05-2009 at 04:54 PM. Reason: confirmed guess changed wording

  • #4
    New Coder
    Join Date
    Jun 2009
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    My try

    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.

    Code:
    <hx:outputLinkEx styleClass="outputLinkEx" id="formPdfLink"
    onclick="return openPDFWord(this, '#{varsearchResults.targetURLForPDF}');" onclick="this.className='afterclick';" 
    value="#{varsearchResults.pdfURL}">
    <h:outputText styleClass="outputText" id="text7"
    value="#{varsearchResults.formIdAndEditionDate}" escape="false"></h:outputText>
    </hx:outputLinkEx>
    Code:
    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:visited{color:#FF0000;} 
    a.afterclick:hover	{color:#FF0000;}


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •