Closed Thread Icon

Preserved Topic: javascript using the clipboard Pages that link to <a href="https://ozoneasylum.com/backlink?for=8851" title="Pages that link to Preserved Topic: javascript using the clipboard" rel="nofollow" >Preserved Topic: javascript using the clipboard\

 
Author Thread
Bmud
Bipolar (III) Inmate

From: Raleigh, NC
Insane since: Mar 2001

posted posted 09-07-2003 05:33

I'd really like to know if there's a function that will copy a string to the clipboard so that I can paste it elsewhere.

someone once told me how to do it via flash with getURL.

code:
javascript:flashToClipBoard('http://www.ozoneasylum.com');


It doesn't seem to work and it's not in my O'Reilly book for JS 1.2

More searching and more code that doesn't work..

code:
<script language="JavaScript">
<!--
function ClipBoard(x) {
Copied = x;
Copied.execCommand("Copy");
}
// -->
</script>

<BUTTON onClick="ClipBoard('test');">Copy
to Clipboard</BUTTON>



A page on MSDN was helpful though it doesn't work out my problem of working with a variable that isn't in a form.

[This message has been edited by Bmud (edited 09-07-2003).]

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 09-07-2003 07:58

Check the code at http://dev.runningwolf.com/code/javascript/decipher.htm
I have copy and paste functions there.

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 09-07-2003 15:36

Bmud: Yep I use Pugzly's functions a lot - very handy.

___________________
Emps

FAQs: Emperor

Bmud
Bipolar (III) Inmate

From: Raleigh, NC
Insane since: Mar 2001

posted posted 09-08-2003 01:44

How about working without forms? Or do I just HAVE to have one?? I'd really like to do this:

code:
<script language="JavaScript">
<!--
function clipBoard(copyString){
copyString.execCommand("Copy");
}
// -->
</script>
<a href="javascript:clipBoard('test');">Copy to Clipboard</a>

Is that possible..?

Shine and shine. :: [Cell=992] :: [See my team's 30 second animation]

Petskull
Maniac (V) Mad Scientist

From: 127 Halcyon Road, Marenia, Atlantis
Insane since: Aug 2000

posted posted 09-08-2003 04:37

question...

why? Isn't this what...um.... variables are for?


Code - CGI - links - DHTML - Javascript - Perl - programming - Magic - http://www.twistedport.com
ICQ: 67751342

Bmud
Bipolar (III) Inmate

From: Raleigh, NC
Insane since: Mar 2001

posted posted 09-11-2003 02:31

Precicely my point. It doesn't work though. try it for yourself.

Shine and shine. :: [Cell=992] :: [See my team's 30 second animation]

GoDon
Obsessive-Compulsive (I) Inmate

From:
Insane since: Sep 2003

posted posted 09-12-2003 18:22

The easiest way to do this in ie 5+ is by using
window.clipboardData.setData("text","copy this text to clipboard");
setData works like this: bSuccess = object.setData(sDataFormat, sData), that means, sDataFormat can be "Text" or "URL", depending on how you want the data to be formatted... so the function would be something like this:
function ClipBoard(x) {
window.clipboardData.setData("text",x);
}

if you want to use the .execCommand("Copy"); you have to use it with a document, controlRange or TextRange.
In your example you tried to use it with a string, which of course doesn't work...

I haven't got the mozilla-dom-information here so i don't know how you have to do it to on moz or ns (but then again, who the hell cares if it doesn't run on netscape??)

Rinswind 2th
Maniac (V) Inmate

From: Den Haag: The Royal Residence
Insane since: Jul 2000

posted posted 09-12-2003 22:10
quote:
(but then again, who the hell cares if it doesn't run on netscape??)


-All the Netscape/ Mozilla /Firebird users
-Any good webdesigner should

Wake up man there is more than only IE in this world (don't think this is meant harsh).

Bmud look at the code from the Jenifer Madden's Select and Copy while you type script You could find a good hint there.

__________________________________________
"Art has to be forgotten. Beauty must be realized."
Piet Mondriaan

GoDon
Obsessive-Compulsive (I) Inmate

From:
Insane since: Sep 2003

posted posted 09-13-2003 20:21

If you create a page for a company or something big, then yes, i agree with you, the page should work on as many browsers as possible... but if you make a page otherwise, just for fun or to show what you can do with dhtm, then forget about netscape/mozilla... users. i mean, how many of them are there now, anyway? (does anyone know the new statistics??) you will just limit yourself. i normally make a page to work on ie and then create a smaller version with less functions for the other browsers. (well, i used to be a netscape-fan, but that was a looong time ago ^_^)
to the clipboard-copy thing: does the execCommand() really work in mozilla? i looked at the mozilla dom and tried Jenifer Madden's page, but it didn't seem to work on mozilla 1.4. and some pages on the internet claim that there isn't a copy to clipboard function in mozilla...
The Version with the execCommand would be:

<textarea id=test></textarea><BR>
<script>
function clipBoard(copyString){
var otext = document.getElementById("test");
otext.innerHTML = copyString;
otext.focus()
otext.select()
var trange = otext.createTextRange()
copyRange = trange.execCommand("Copy");
}
</script>
<a href="javascript:clipBoard('test');">Copy to Clipboard</a>

------------
ps: you can not make something fun like this: www.dreamweb.ch/don/desktop
on an other browser than ie... (this is just a beta-version of my new page. i'm gonna change the skin in the final version, of course, or else i might have some copyright-problems with microsoft ^_^. )

Rinswind 2th
Maniac (V) Inmate

From: Den Haag: The Royal Residence
Insane since: Jul 2000

posted posted 09-14-2003 00:51

[off-topic]
You are not going todrag me in a "IE is better than Mozilla" discussion.
The 'fun' site you linked did not work in Moz. But it looked like you disabled MY controls and that's nowhere near fun.


According to this this Gecko based browsers take 2.3% till 14%of marketshare times a couple off million people who surf the web some hundred of thousands people use moz, netscape or firebird, thats anawfull lot.
On this site there is some good arguments against these stats...[/off-topic]

__________________________________________
"Art has to be forgotten. Beauty must be realized."
Piet Mondriaan

GoDon
Obsessive-Compulsive (I) Inmate

From:
Insane since: Sep 2003

posted posted 09-14-2003 03:19

sorry, didn't want to drag you into a "IE is better than Mozilla" discussion, and the page i linked to wasn't supposed to be running on mozilla (that was the whole point of it) and 2.3% till 14% aren't that many users considering that most of them have ie installed as well (most of my friends have all browsers installed, just to test if all the pages really work on all the browsers), and sorry that you didn't like that i disabled YOUR controls, but the page with the statistics was fascinating anyway ...[/off-topic]

Bmud
Bipolar (III) Inmate

From: Raleigh, NC
Insane since: Mar 2001

posted posted 09-14-2003 15:38

This is what I came up with. I know I can't use a string with execCommand. I'm sticking to the function, because as far as I know, it's cross-platform. So I threw in a tiny form that eats up my string, then i select it, copy it. ta-da

Only problem I have now is focus(). focusing on the text field to copy the teaxt means that the page moves UP to where to text field is. I'd rather not have that happen..

While I'm at it, I'll say that redirecting one of my iframes to an anchor ( ...blahblah.html#thisSpecificThing ) makes the entire document taylor to that part of the page as well.

thirdly, is there a "refresh" function?

Shine and shine. :: [Cell=992] :: [See my team's 30 second animation]

« BackwardsOnwards »

Show Forum Drop Down Menu