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
rebvijkumrebvijkum 

copy the url to clipboard if i click on hyperlink

Hi, 
    I have a hyperlink in visualforce page, if i click on hyperlink, the value should copy to clipboard

my vfp code;
<apex:outputLink  value="https://{!sfurll}/apex/CoreBenefit_PDF?id={!Returnid}" target="_blank" styleClass="newlink" >
Copy Url
</apex:outputLink>

If i click on "Copy Url", the "https://c.ap1.visual.force.com/apex/CoreBenefit_PDF?id=kA690000000H1An" should be saved in clipboard
Deepak Kumar ShyoranDeepak Kumar Shyoran
Use below code to copy URL in clipboard.
<script>
function copyToClipboard(text) 
{
if (window.clipboardData && clipboardData.setData) {
    clipboardData.setData("Text", text);
}
}
</script>

<apex:outputLink onclick="copyToClipboard('https://{!sfurll}/apex/CoreBenefit_PDF?id={!Returnid}');" value="https://{!sfurll}/apex/CoreBenefit_PDF?id={!Returnid}" target="_blank" styleClass="newlink" >
Copy Url
</apex:outputLink>

You can also modified the above code as per your need also.
rebvijkumrebvijkum
Thanks for the reply but it doesn't work, it simply opens the page with url=https://c.ap1.visual.force.com/apex/CoreBenefit_PDF?id=kA690000000H1An.
Do i need to include any script???


My code:
<apex:page standardController="Core_Benefit__kav" extensions="GetURL" standardStylesheets="false" id="corebenefit"  sidebar="false">
 
  <script>
function copyToClipboard(text)
{
if (window.clipboardData && clipboardData.setData) {
    clipboardData.setData("Text", text);
}
}
</script>
   
<apex:outputLink onclick="copyToClipboard('https://{!sfurll}/apex/CoreBenefit_PDF?id={!Returnid}');" value="https://{!sfurll}/apex/CoreBenefit_VFP?id={!Returnid}" target="_blank">
Copy Url
</apex:outputLink>      
</apex:page> 
Kiran  KurellaKiran Kurella
I have used ZeroClipboard library in the past and it worked fine on all browsers.

http://zeroclipboard.org/
rebvijkumrebvijkum
i've downloaded the zipfile, can u please tell me how can i use the zipfile to solve my requirement??
Thanks again for replying
Deepak Kumar ShyoranDeepak Kumar Shyoran
You need to extrect file from downloaded Zip and the need to use them on VF page. See this link to use ZeroClipboard

https://github.com/zeroclipboard/zeroclipboard/blob/master/README.md
rebvijkumrebvijkum
i got the ZeroClipboard.js file from zipfile and created main.js with the code they given in https://github.com/zeroclipboard/zeroclipboard/blob/master/README.md and refered both scripts in visualforce page using <apex:include>. and i used
<body>
            <button id="copy-button" data-clipboard-text="https://{!sfurll}/apex/CoreBenefit_VFP?id={!Returnid}" title="Click to copy me.">Copy to Clipboard</button>          
        </body>

it doesn't work, any suggestions?
should i write any script within vfp?