User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 361,909 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,483 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 4221 | Replies: 1
Reply
Join Date: Jul 2006
Posts: 11
Reputation: jeadeb is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
jeadeb jeadeb is offline Offline
Newbie Poster

Copy text to clipboard

  #1  
Aug 29th, 2006
Hi there all

I am in the process of developing a knowledgebase..

I have some cool click and copy script but it doesnt allow me to format the text that is copied so that I can copy an already fromatted email..

for example:

Hi,

thank you for contacting us, blablablablablablablablablablabla
blablablablablablablablablablablablablablablablabla

Kind regards

blabla.


here is the jscript I have:

[html]
<script language="javascript" type="text/javascript">
<!--
function copy_clip(meintext)
{
if (window.clipboardData)
{

window.clipboardData.setData("Text", meintext);

}
else if (window.netscape)
{

netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

var clip = Components.classes['@mozilla.org/widget/clipboard;1']
.createInstance(Components.interfaces.nsIClipboard);
if (!clip) return;

var trans = Components.classes['@mozilla.org/widget/transferable;1']
.createInstance(Components.interfaces.nsITransferable);
if (!trans) return;

trans.addDataFlavor('text/unicode');

var str = new Object();
var len = new Object();
var str = Components.classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString);
var copytext=meintext;
str.data=copytext;
trans.setTransferData("text/unicode",str,copytext.length*2);
var clipid=Components.interfaces.nsIClipboard;
if (!clip) return false;
clip.setData(trans,null,clipid.kGlobalClipboard);
}
alert("The following text has been copied:\n\n" + meintext);
return false;
}
//-->
</script>


<p><span onclick='return copy_clip("this text will be copied to clipboard'>
when you click on this text, the above is copied.(but you cant see it untill you paste it.
</span> </p>
[/html]

here is my problem.


I cant format any thing in this area

<p><span onclick='return copy_clip("this text will be copied to clipboard'>

I get that jscript error if i try...


I want to for example, do something like this:

<p><span onclick='return copy_clip("hi there,
<p>thank you for contacting us etc</p>")'>


so that when pasted you can have a nicely formatted email/...


Please HELP

thanks!!
Last edited by tgreer : Aug 29th, 2006 at 9:44 am. Reason: User ignored rule regarding code tags.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Posts: 1,589
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 34
Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: Copy text to clipboard

  #2  
Aug 29th, 2006
First, there is a difference between Jscript and JavaScript. They are two different languages. Second, I don't know of any OS that will copy fully-formatted HTML to the clipboard. Sorry.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 9:35 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC