C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » JavaScript »

'OpenClipboard Failed' error is giving when try to copy clipboard using javascript


Posted Date: 05 Nov 2009      Posted By: Challa SudhakarReddy      Member Level: Gold     Points: 1   Responses: 2



Hi

Particular column data of selected rows from gridview should be copied into windows clipboard. And the following code is doing that. But we are getting the error some times, and error is "OpenClipboard Failed"



<script language="javascript" type="text/javascript">

function CopyToclipboard() {

var TargetBaseControl = document.getElementById('gvSearchResult');

var Inputs = TargetBaseControl.getElementsByTagName("input");
var TargetChildControl = "chkSelectbox";
var x = '';
window.clipboardData.clearData();
debugger
for (var n = 0; n < Inputs.length; n++) {

if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl, 0) >= 0 && Inputs[n].checked) {

x = x +"\r\n" + TargetBaseControl.rows[n + 1].cells[3].innerText;


}
window.clipboardData.clearData('Text');
window.clipboardData.setData('Text', x);

}

return false;
}


</script>





Responses

Author: Lalji    05 Nov 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

show this sample code
<html>
<head>
<title>Copy select</title>
<script>
/* Function to copy a selection to clipboard
Copyright (c) 2001 Michel Plungjan javascripts(a)planet.nl */

function copyText(theSel) {
if (!document.all) return; // IE only
theForm = theSel.form;
theForm.copyArea.value=theSel.options[theSel.selectedIndex].value;
r=theForm.copyArea.createTextRange();
r.select();
r.execCommand('copy');
}
</script>

</head>

<body>
<form>
<select onChange="copyText(this)">
<option value="">Please select
<option value="alpha">A
<option value="bravo">B

</select>
<input type="hidden" name="copyArea" value="">
</form>


</body>
</html>

more reference
-----------------
http://www.frontpagewebmaster.com/m-185852/tm.htm
http://davidwalsh.name/clipboard



Author: vipul    05 Nov 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

hi,
if you running this on firefox then it is possible to get error (because your code is only work on microsoft ie) for running that into mozzila you can refer this link
http://www.gamedev.net/community/forums/topic.asp?topic_id=281951

Please Rate This Answer If They Helpful

Thanks & Regards
Patel Vipul



Post Reply
You must Sign In to post a response.
Next : How to create Dynamically Dropdown list
Previous : Calender Control
Return to Discussion Forum
Post New Message
Category: JavaScript

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use