我已成功在Chrome,Firefox和IE上安装了我的crossrider扩展程序(全部都是最新的),但浏览器按钮(虽然全部启用)仅适用于Chrome。
后台代码似乎有效,因为我可以触发警报。
我的background.js看起来像这样:
appAPI.ready(function() {
var popupDims = {
CH: {height: 400, width: 400},
FF: {height: 400, width: 400},
IE: {height: 400, width: 400},
SF: {height: 400, width: 400}
};
if ("CHFFIESF".indexOf(appAPI.platform) !== -1) {
appAPI.browserAction.setPopup({
resourcePath:'popup.html',
height:popupDims[appAPI.platform].height,
width:popupDims[appAPI.platform].width
});
}
else {
alert('This extension is not supported on your browser');
}});
在我的popup.html中,我有一些javascript:
function crossriderMain($) {
// load libraries
eval(appAPI.resources.get('select2.js'));
$('[as-trigger]').click(function () {
// retrieves the information for the active tab
appAPI.tabs.getActive(function(tabInfo) {
activeUrl = tabInfo.tabUrl;
appAPI.request.get({
url: 'http://...',
onSuccess: function(response, additionalInfo) {
// show message
},
onFailure: function(httpCode) {
console.log('GET:: Request failed. HTTP Code: ' + httpCode);
}
});
});
})
$('[as-project-dropdown]').select2().on('select2-selecting', function (e) {
// some jquery code
});
appAPI.request.get({
url: 'http://...',
onSuccess: function(response, additionalInfo) {
var dataObject = JSON.parse(response);
$.each(dataObject.data, function(key, value) {
$('[as-project-list]').append('some html...');
});
$('[as-companyname]').html(dataObject.company);
},
onFailure: function(httpCode) {
console.log('GET:: Request failed. HTTP Code: ' + httpCode);
}
});}
在我的firefox控制台中,我可以看到我的扩展程序抛出错误:
MyExtension <Warning: document.getElementById(...) is null Function-name: appAPI.request.get User callback>
@Crossrider支持:我的应用ID为65982
答案 0 :(得分:1)
查看您的代码我可以看到您没有设置浏览器操作的图标。根据{{3}},在某些浏览器上,这对按钮正确初始化至关重要。我使用您的代码创建了一个扩展程序,并使用Browser Action docs添加了图标,按钮工作正常。
所以从你的background.js中获取片段,添加如下图标:
appAPI.ready(function() {
var popupDims = {
CH: {height: 400, width: 400},
FF: {height: 400, width: 400},
IE: {height: 400, width: 400},
SF: {height: 400, width: 400}
};
if ("CHFFIESF".indexOf(appAPI.platform) !== -1) {
appAPI.browserAction.setResourceIcon('logo.jpg');
appAPI.browserAction.setPopup({
resourcePath:'popup.html',
height:popupDims[appAPI.platform].height,
width:popupDims[appAPI.platform].width
});
}
else {
alert('This extension is not supported on your browser');
}});
[披露:我是一名Crossrider empployee]