开发者

How to paste a text to the browser?

Following this tutorial I was able to retrieve data form the clipboard.

But I have no idea (nither there's something in the API) about how to insert my string into the xul browser (say, when the user open the 'edit' menu and click 'paste').

Any idea?

--update

There's a cmd_paste here, but there's no hint if I can (and how to) use it to paste in a browser. Also the browser's API available documentation have nothing about.

I tried make it work creating a browser, setting the command attribute (not sure if it exists, the API says nothing, but it's a wiki not much reliable) and a button to paste:

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window width="400" height="300"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

    <browser id="mybrowser" command="cmd_paste" type="content" src="http://www.google.com/" flex="1" />
    <button label="TEST PASTE" command="document.getElementById('mybrowser').doCommand();" />

</window>

Nothing happens when I press the button开发者_如何学运维 (with data on my clipboard, and a text field selected inside the browser).

--in the xulrunner source

within toolkit.jar, at content/global/editMenuOverlay.xul there's the definition:

<command id="cmd_paste" oncommand="goDoCommand('cmd_paste')"/>

but no "goDoCommand" method is defined there, nither in the only javascript file included: editMenuOverlay.js.


Do you really need a "paste" command? Couldn't you just retrieve the data from the clipboard using the tutorial you found and copy it into the currently focused text elements when the past button is pressed?


After finding the goDoCommand (see the question update) I found out that the function was in the globalOverlay.js file.

So I added to my Xul:

<script type="application/x-javascript" src="chrome://global/content/globalOverlay.js" />

and used the goDoCommand command.

Not yet sure if it's the best or even correct approach to add this js to my Xul, but look likes ok.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜