function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tyler Harris 8Tyler Harris 8 

Pass clicked link to Apex variable?

Hello all,

I have a link that I want passed to a String Variable in the Controller onclick. I'm failing at accomplishing this. Any help would be useful.

Visualforce
 
<apex:form >
             
    <apex:actionRegion >
    <apex:actionFunction name="setLink" action="{!makeLink}" reRender="link">
        <apex:param name="param1" assignTo="{!setLink}" value="" />
      </apex:actionFunction>
    </apex:actionRegion>
      
</apex:form>  
<a id="downloadContent" href="{!$Site.Prefix}/sfc/servlet.shepherd/version/download/{!con.Id}" onclick="setLink()"><i class="fa fa-download"></i></a>

Apex
public String linkClick{
     get;set;
        
    }
    
    public PageReference makeLink(){
        return null;
        
    }

 
Best Answer chosen by Tyler Harris 8
SalesFORCE_enFORCErSalesFORCE_enFORCEr
You need to add get set for setLink in your controller and replace anchor tag with this
<a id="downloadContent" href="{!$Site.Prefix}/sfc/servlet.shepherd/version/download/{!con.Id}"onclick="setLink(this.href)"><i class="fa fa-download"></i></a>