I am working on writing an extension that will, add the selected text
to the Firefox context menu. Something like the "Google for XYZ" which
you see if you select "XYZ" text on the screen and right click on it.
I have tried unsuccessfully with this.getSelection() &
this.getAttribute("id") for some time but it did not work out.
event.getSelectedText() also does not seem to working.
Can someone help/ guide me through the process so that I can create my
own Firefox extension?
Thanks in advance
-- Manish Chakravarty
my code (for overlay.js ) is posted below:
var HelloWorld = {
onLoad: function() {
// initialization code
this.initialized = true;
this.strings = document.getElementById("recorderpopup-strings");
document.getElementById("contentAreaContextMenu")
.addEventListener("popupshowing", function(e)
{ this.showContextMenu(e); }, false);
},
onMenuItemCommand: function(event) {
// window.open("chrome://helloworld/content/hello.xul", "",
"chrome");
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-
service;1"]
.getService
(Components.interfaces.nsIPromptService);
var foo = this;
promptService.alert(window,this.getSelection(),this.getAttribute
("id"));
},
showContextMenu: function(event) {
// document.getElementById("context-recorderpopup").hidden =
gContextMenu.onImage;
},
};
window.addEventListener("load", function(e) { HelloWorld.onLoad(e); },
false);
The getBrowserSelection function does that, the "Google for XYZ"
thing you described, you can find it here:
http://mxr.mozilla.org/mozilla-central/source/browser/base/content/browser.js#4686
But basically with window.getSelection().toString(), you get the
selected text as a string, see also:
https://developer.mozilla.org/en/DOM/window.getSelection
Regards,
Martijn
> _______________________________________________
> dev-mdc mailing list
> dev...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-mdc
>
--
Martijn Wargers - Help Mozilla!
http://quality.mozilla.org/
http://wiki.mozilla.org/Mozilla_QA_Community
irc://irc.mozilla.org/qa - /nick mw22
The information you provided indeed proved useful.
Can you please write some code and show me an example? A simple
example that pops up the selected text in the an alert or something
like that..
Thanks,
Manish
On Jul 16, 11:07 pm, Martijn <martijn.mart...@gmail.com> wrote:
> On Thu, Jul 16, 2009 at 11:15 AM, Manish
>
> Chakravarty<manishch...@gmail.com> wrote:
> > Hello,
>
> > I am working on writing an extension that will, add the selected text
> > to the Firefox context menu. Something like the "Google for XYZ" which
> > you see if you select "XYZ" text on the screen and right click on it.
>
> > I have tried unsuccessfully with this.getSelection() &
> > this.getAttribute("id") for some time but it did not work out.
> > event.getSelectedText() also does not seem to working.
>
> > Can someone help/ guide me through the process so that I can create my
> > own Firefox extension?
>
> The getBrowserSelection function does that, the "Google for XYZ"
> thing you described, you can find it here:http://mxr.mozilla.org/mozilla-central/source/browser/base/content/br...
> > dev-...@lists.mozilla.org
> >https://lists.mozilla.org/listinfo/dev-mdc
>
> --
> Martijn Wargers - Help Mozilla!http://quality.mozilla.org/http://wiki.mozilla.org/Mozilla_QA_Community