ID:273280
 
Hi, I'm trying to add a "copy" button on my interface to add text to my clipboard.

When I asked for help on this before someone gave me this;
client/New()
..()
world << browse({"
<html>
<head>
<script type="text/javascript">
var clipText = window.clipboardData.getData('Text');
//window.clipboardData.setText('Text', 'my text here') to set clipboard text
document.write(clipText);
</script>
</head>
<body>
</body>
</html>
"}
)


I adjusted it to fit my means (also note, I know nothing about javascript);


mob
verb
Copy()
src << browse({"
<html>
<head>
<script type="text/javascript">
var clipText = window.clipboardData.getData('Text');
window.clipboardData.setText('Text', '
[toc]');
document.write(clipText);
</script>
</head>
<body>
</body>
</html>"}
)


I've also tried

        <script type="text/javascript">
var clipText = wwindow.clipboardData.setData('Text', '[toc]');
document.write(clipText);
</script>

It no work. :(
I think from a security perspective, you have to enable this functionality through the inetcpl or equivalent security setting depending on your browser.

In response to Tsfreaks
/doesn't understand/
So, there's no way to make this work through DM? :o
In response to Super Saiyan X
You can but you will get prompted to copy right?

<script>

//Copytext to clipboard- by Gennero (patrice.gennero@voila.fr)
//Submited to DynamicDrive.com
//Visit http://www.dynamicdrive.com for this 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) {
alert(copiedtext);
}
bBool=false;
}
}

document.onselectionchange = initiatecopy
document.onmouseup = copyit

</script>
In response to Tsfreaks
Heh, give me a sec... I did end up solving this...
What are you trying to copy exactly? Content from a byond control?

ts
In response to Tsfreaks
I think that's only for reading from the clipboard, not writing to it.

Nevermind, thinking about Flash (which would be one workaround)
In response to Tsfreaks
I have a variable, named 'toc'. (which is also displayed in a label)

What I am attempting to do, is so when I click the button control, "Copy", which calls the verb, "Copy" it adds whatever 'toc' is (which is also the contents of the label's text parameter)
In response to Super Saiyan X
OK, so, is it acceptable to get prompted with a, do you want to allow this webpage to copy content to your keyboard?

ts
In response to Tsfreaks
Sure, I was gonna add a 'This will copy [whatever you're copying] to your clipboard' anyways. So, whatever other prompt is fine.
In response to DarkCampainger
You can test that script here (with ie)

http://www.dynamicdrive.com/dynamicindex11/copytext.htm
In response to Super Saiyan X
Then that script will work. Test it out. Then just send your content to a webpage. I can help with that part if you need it.
In response to Super Saiyan X
I'll throw a demo together real quick.

ts
Good news for us! I got it working without the alert.

Dirty Demo

ts

In response to Tsfreaks
Ran the DMB, looks like its working. Thanks, I'll look over the html file and stuff tommorrow.

Hmm, I wonder though, is it possible to get it work without the HTML file?
In response to Super Saiyan X
Not sure if you can. You can hide the browser window though so its a matter of reducing your weight a little bit.

ts