【问题标题】:crossrider extension installed on all browsers but working only in chromecrossrider 扩展安装在所有浏览器上,但仅在 chrome 中工作
【发布时间】:2014-10-20 11:54:14
【问题描述】:

我已在 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

【问题讨论】:

    标签: javascript google-chrome-extension firefox-addon crossrider


    【解决方案1】:

    查看您的代码,我可以看到您没有设置浏览器操作的图标。根据Browser Action docs,在某些浏览器上,这对于正确初始化按钮至关重要。我使用您的代码创建了一个扩展,并使用appAPI.browserAction.setResourceIcon 添加了图标,并且按钮工作正常。

    所以从你的 background.js 中获取 sn-p,添加图标如下:

    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 员工]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-14
      • 2015-09-02
      • 1970-01-01
      相关资源
      最近更新 更多