Firefox Xul Clipboad [英] Firefox Xul Clipboad

查看:86
本文介绍了Firefox Xul Clipboad的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程世界的新手&我正在尝试为Firefox开发扩展程序。我有一个带文本框的Xul窗口,我想复制整个文本框并放入firefox的剪贴板中,然后将其粘贴到firefox浏览器的任何位置。

I'm new to the programming world & i'm trying to develop an extension for Firefox. I have a Xul window with a textbox and i would like to copy the entire textbox and put in to the clipboard of firefox and paste it anywhere on the firefox browser.

帮助我用一些JS代码或使用xul编码。

Help me out with some JS code or using xul coding.

请帮帮我或给我一些建议。

Please help me out or give me some suggestion.

在此先感谢大家。

推荐答案

我的问题已解决:

这是脚本:此脚本复制文本框中的整个文本,您可以将其粘贴到浏览器Firefox中的任何位置。

Here is the script: This script copy the entire text from the textbox and you can paste it anywhere in the browser Firefox.

<!-- Following script is for copy & paste function -->

<script>    

<![CDATA[
 function copyToClipboard() { 

//Select all the text/strings from the textbox.
var copytext=document.getElementById('tb').value; 

//alert(document.getElementById('tb').value + 'This is  XUL');

//An XPCOM wrapper for the data which you want to put on the clipboard.
var str = Components.classes["@mozilla.org/supports-string;1"].
createInstance(Components.interfaces.nsISupportsString);
if (!str) return false;
str.data = copytext;

//This object is the component @mozilla.org/widget/transferable;1 which implements the interface nsITransferable.

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

trans.addDataFlavor("text/unicode");
trans.setTransferData("text/unicode", str, copytext.length * 2);

var clipid = Components.interfaces.nsIClipboard;
var clip = Components.classes["@mozilla.org/widget/clipboard;1"].getService(clipid);
if (!clip) return false;

clip.setData(trans, null, clipid.kGlobalClipboard);

//alert(document.getElementById('tb').value + 'This is fuckin XUL');

pasteFromClip();

window.close();
} 

function pasteFromClip() { 

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

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

clip.getData(trans, clip.kGlobalClipboard); 
var str = new Object(); 
var len = new Object(); 
trans.getTransferData("text/unicode",str,len); 

str = str.value.QueryInterface(Components.interfaces.nsISupportsString); 
str = str.data.substring(0, len.value / 2); 
return document.createTextNode(str); 

} 

]]>

</script>

这篇关于Firefox Xul Clipboad的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆