Firefox Xul 剪贴板

发布于 2024-11-02 00:53:57 字数 184 浏览 1 评论 0原文

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

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

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

提前谢谢你们了。

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.

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

Please help me out or give me some suggestion.

Thanking you guys in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

做个少女永远怀春 2024-11-09 00:53:57

要将文本复制到剪贴板,最简单的方法是使用剪贴板助手服务。

For copying text to the clipboard the easiest way is to use the clipboard helper service.

几度春秋 2024-11-09 00:53:57

我的问题已解决:

这是脚本:该脚本从文本框中复制整个文本,您可以将其粘贴到 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>

My Problem is Fixed :

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文