window.open document.write在Chrome上有效,但在Firefox上不可用

时间:2018-09-12 18:09:21

标签: google-chrome-extension firefox-addon firefox-webextensions window.open

我们有一个chrome Web扩展程序,可以正常运行,而我们没有移植到Firefox的问题,我们在内容脚本上有一些代码,在Chrome浏览器中可以正常工作

try {
        let bootstrapCss = chrome.extension.getURL("content/bootstrap.min.css");
        var printWindow = window.open('', "_blank", 'location=no,toolbar=0');           
        printWindow.document.write(`<html><head><link rel="stylesheet" href="${bootstrapCss}"></head><body>${html}</body></html>`);
        printWindow.document.close();

        this._logger.logInfo("Print window object");
        this._logger.logInfo(printWindow);          
    } catch (error) {
        this._logger.logError("Error creating print window");
        this._logger.logError(error);
    }

    setTimeout(() => {      
        printWindow.print();
        printWindow.close();
    }, 200);

但是,当我们在Firefox上运行此代码时,会出现以下错误:

  

SecurityError:拒绝访问以下属性“文档”的权限   跨域对象

无论如何,在我们试图保持单一代码库的情况下,是否可以在Firefox上运行该功能,或者在Firefox和Chrome上都可以运行的功能。

0 个答案:

没有答案
相关问题