/    Sign up×
Community /Pin to ProfileBookmark

Help with clipboard

I was wondering if this script could be converted to work with Firefox?

[code]
function ClipBoard()
{
holdtext.innerText = copytext.innerText;
Copied = holdtext.createTextRange();
Copied.execCommand(“RemoveFormat”);
Copied.execCommand(“Copy”);
}

<SPAN ID=”copytext” STYLE=”display:none;”>

Reason for requesting replacement: <?php echo $rfr;?><br>
Make/Model Number: <?php echo $mk; ?> , <?php echo $md; ?><br>
WDS: <?php echo $wd; ?><br>
Serial Number: <?php echo $sn; ?><br>
MAC Address: <?php echo $ma; ?><br>
IP Address: <?php echo $ip; ?><br>
Property ID: <?php echo $pp; ?><br>
Property Contact Name/Title: <?php echo $ct; ?><br>
Shipping Severity: <?php echo $sp; ?><br>
Ticket #: <?php echo $tt; ?><br>
Comments: <?php echo $cm; ?><br>
</span>

<TEXTAREA ID=”holdtext” STYLE=”display:none;”>

</TEXTAREA>

[/code]

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Nov 30.2006 — http://www.google.com/search?q=JavaScript+copy+to+clipboard+firefox

Always Google first!

FYI: browsers have settings now to block it.

Eric
Copy linkTweet thisAlerts:
@prophitauthorNov 30.2006 — i did google it.. i was asking if there was away to convert my already working script for IE and make it work for firefox. The few scripts i have found that work for firefox require a text area. I cant seem to get those scripts to function properly inside of a text box. Thanks for the help though..
Copy linkTweet thisAlerts:
@prophitauthorNov 30.2006 — ok well i was able to adapt a script that works in both Ie and firefox and still will copy what i needed it to copy. Took a bit of hangling around but finally was able to get this to work
Copy linkTweet thisAlerts:
@justinbarneskinNov 30.2006 — Oh, you're keeping it a secret then, are ya?
Copy linkTweet thisAlerts:
@prophitauthorNov 30.2006 — lol ok here is the script that i found
<i>
</i>&lt;script&gt;
function copy_clip(meintext){

<i> </i>if (window.clipboardData){
<i> </i> window.clipboardData.setData("Text", meintext);
<i> </i>}else if (window.netscape){
<i> </i> netscape.security.PrivilegeManager.enablePrivilege ('UniversalXPConnect');

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

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

<i> </i> trans.addDataFlavor('text/unicode');

<i> </i> var str = new Object();
<i> </i> var len = new Object();

<i> </i> var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
<i> </i> var copytext=meintext;
<i> </i> str.data=copytext;
<i> </i> trans.setTransferData("text/unicode",str,copytext.length*2);
<i> </i> var clipid=Components.interfaces.nsIClipboard;

<i> </i> if (!clip) return false;
<i> </i> clip.setData(trans,null,clipid.kGlobalClipboard);

<i> </i>}

<i> </i>return false;
}
//--&gt;
&lt;/script&gt;

&lt;form name="testform"&gt;
&lt;pre&gt;
&lt;textarea name="testsquare" rows="20" cols="56" &gt;

&lt;?php echo $form; ?&gt;

&lt;/textarea&gt;
&lt;/pre&gt;
&lt;input type="button" onclick="return copy_clip(document.forms[0].testsquare.value)" value="Copy to Clipboard"&gt;
&lt;/form&gt;


Now if you look inside of the textarea i have an echo command there for php. The only way i could get this to work properly was to add in a little php to make the form and then echo into the textarea.

here is the php code
&lt;?php
$rfr = $_POST['rfr'];
$mk = $_POST['make'];
$md = $_POST['model'];
$wd = $_POST['wds'];
$sn = $_POST['sn'];
$ma = $_POST['mac'];
$ip = $_POST['ipaddr'];
$pp = $_POST['prop'];
$ct = $_POST['contact'];
$sp = $_POST['ship'];
$tt = $_POST['ticket'];
$cm = $_POST['status'];



$form = "
Reason for requesting replacement: $rfr
Make/Model Number: $mk , $md
WDS: $wd
Serial Number: $sn
MAC Address: $ma
IP Address: $ip
Property ID: $pp
Property ContactName/Title: $ct
Shipping Severity: $sp
Ticket Number: $tt
Comments: $cm
";
?&gt;

I hope this helps anyone that is having problems with getting FF to copy to the clipboard. Now here is another thing. Im only doing this cause its for a intranet site. No outside world will be seeing or using this script. So i enabled javascript on the browsers.

Enjoy!!
×

Success!

Help @prophit 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 5.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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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