Created
May 3, 2017 18:21
-
-
Save nithesh1992/dc66708bde9ab94313a731a715fef9ad to your computer and use it in GitHub Desktop.
Visualforce Copy to CLIPBOARD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page title="Clipboard Test" > | |
<apex:messages /> | |
<script language="JavaScript"> | |
function ClipBoard(copytextid, holdtextid){ | |
copyToClipboard(copytextid); | |
} | |
function copyToClipboard(elementId) { | |
// Create an auxiliary hidden input | |
var aux = document.createElement("input"); | |
// Get the text from the element passed into the input | |
aux.setAttribute("value", document.getElementById(elementId).innerHTML); | |
// Append the aux input to the body | |
document.body.appendChild(aux); | |
// Highlight the content | |
aux.select(); | |
// Execute the copy command | |
document.execCommand("copy"); | |
// Remove the input from the body | |
document.body.removeChild(aux); | |
} | |
</script> | |
<apex:pageblock > | |
<apex:form > | |
<apex:outputpanel ID="copytext" STYLE="height:150;width:162;background-color:pink"> | |
Text to Copy | |
</apex:outputpanel> | |
<apex:inputtextarea ID="holdtext" STYLE="display:none;"></apex:inputtextarea> | |
<apex:commandbutton onClick="ClipBoard('{!$Component.copytext}', '{!$Component.holdtext}');" rerender="copytext" value="Copy to Clipboard"/> | |
</apex:form> | |
</apex:pageblock> | |
</apex:page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment