MozillaZine

gContextMenu changed and screwed up my extension

Talk about add-ons and extension development.
blindtrust
 
Posts: 18
Joined: September 10th, 2005, 9:18 am

Post Posted September 10th, 2005, 9:29 am

Hi,

in an extension I hacked together I used
var theurl = gContextMenu.linkURL();

But now in Firefox 1.4 (1.5b1) it doesn't work anymore. Looking at FF 1.0 browser.js vs. FF trunk browser.js I discovered that gContextMenu has changed.

So If I now write
var theurl = gContextMenu.linkURL;
it works like it should. But then the extension doesn't work in FF 1.0.x and Seamonkey anymore. So my questions:
1. Am I wrong in using gContextMenu.linkURL with or without braces at all? Is there an always working alternative?
2. If not, is there a way to recognize what browser executes the extension in order to use the right instruction?

I can make it work using
try {
var theurl = gContextMenu.linkURL();
} catch(e) {
var theurl = gContextMenu.linkURL;
}

but that's not nice. And there might be other changes which will not be catchable this way.

cheers,
RBM

Philip Chee

User avatar
 
Posts: 6475
Joined: March 1st, 2005, 3:03 pm

Post Posted September 10th, 2005, 12:19 pm

How about (untested code):
Code: Select all
var theUrl = gContextMenu.linkURL;
if ( typeof(theURL) == "function" )
  theURL = theURL();

onemen

User avatar
 
Posts: 1130
Joined: October 15th, 2004, 7:48 am

Post Posted September 10th, 2005, 1:21 pm

Code: Select all
var theurl = typeof(gContextMenu.linkURL) == "function"  ? gContextMenu.linkURL() : gContextMenu.linkURL;


or since getLinkURL function replace linkURL function in the trunk so u can use
Code: Select all
var theurl = (getLinkURL  in gContextMenu )  ? gContextMenu.linkURL : gContextMenu.linkURL();

blindtrust
 
Posts: 18
Joined: September 10th, 2005, 9:18 am

Post Posted September 11th, 2005, 6:21 am

Good points, Philip and onemen, this is both nice.

I guess I use Philip's code since it's the more general one. But assigning gContextMenu.linkURL() directly and not using theURL() is necessary as onemen wrote.

Thank you both, guys!

RBM

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 2 guests