/    Sign up×
Community /Pin to ProfileBookmark

cpoy to clip board

hi,

I want to copy a string into clipboard through javascript.I tried this.
strcpy=”Hi”
clipboard.SetDataObject(strcpy, true);
not working.

and how do i copy the value of a hiddencontrol in a aspx page to clip board

Clipboard.SetDataObject(hdnval.value, true)–not working.Its copying hdnval to clipboard..

Is there any serverside code in C# for this?

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@amithauthorMar 26.2008 — This worked for me.

clipboardData.setData("Text", strcpy);

Is there any way to do this on client side? C# ASP.NET webapplication?
Copy linkTweet thisAlerts:
@lorkanMar 26.2008 — This is a script that copies everything you select to clipboard.

If you don't want the whole script (the part that it will copy anything you select from the page) you can take out parts from it...

[CODE]<script>

bBool=false
var copiedtext=""
var tempstore=""

function initiatecopy() {
bBool=true;
}

function copyit() {
if (bBool) {
tempstore=copiedtext
document.execCommand("Copy")
copiedtext=window.clipboardData.getData("Text");
if (tempstore!=copiedtext) {
//This is if you want to alert the copied text...
//alert(copiedtext);
}
bBool=false;
}
}

document.onselectionchange = initiatecopy
document.onmouseup = copyit

</script>[/CODE]
Copy linkTweet thisAlerts:
@felgallMar 26.2008 — You really should add a test for whether the browser supports document.execCommand so that browsers other than IE don't give an error on that code.
Copy linkTweet thisAlerts:
@lorkanMar 26.2008 — IE7 doesn't usually allow copying text. What I get is an alert every first time i copy asking if I allow the page to copy to clipboard.
Copy linkTweet thisAlerts:
@felgallMar 27.2008 — Well if a web page could load the clipboard with a virus without your knowledge it could compromise the security of your computer. That's one of the reasons that browsers (other than IE) don't allow access to the clipboard directly from the web page at all.
×

Success!

Help @amith spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...