我正在使用 Angular 8 创建一个库来从 Pentaho CTools 呈现仪表板以避免使用 iframe。如果我直接从 index.html 调用脚本,它可以正常工作,因此我可以渲染仪表板。但在我的情况下,我需要从 appendChild 注入它,这样我就可以更动态地插入用户 ID、密码和 pentaho url。
const url = `${pentahoHost}${PENTAHO_URL}userid=${userId};password=${password};port=433`;
const scriptId = 'pgi-pentaho';
const script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
script.id = scriptId;
document.head.appendChild(script);
但是当我运行该应用程序时,它会给我以下消息:
无法在“文档”上执行“写入”:除非显式打开,否则无法从异步加载的外部脚本写入文档。
这就是我从 Pentaho 服务器的调用中得到的:
/** This file is generated in cdf to allow using cdf embedded.
It will append to the head tag the dependencies needed, like the FULLY_QUALIFIED_URL**/
var requireCfg = {waitSeconds: 30, paths: {}, shim: {}, map: {"*": {}}, bundles: {}, config: {service: {}}, packages: []};
requireCfg.config['cdf/dashboard/Dashboard'] = {
context: {"path":"","serverLocalDate":1610033507192,"queryData":{},"roles":["Administrator","Authenticated"],"sessionTimeout":7200,"sessionAttributes":{},"locale":"en_US","params":{},"serverUTCDate":1610033507192,"user":"admin"},
storage: {}
};
// injecting document writes to append the cdf require files
document.write("<script language='javascript' type='text/javascript' src='http://localhost:4200/pentaho/content/cte/resources/editor/cte-require-js-cfg.js'></script>");
document.write("<script language='javascript' type='text/javascript' src='http://localhost:4200/pentaho/content/twelve-days-visualizations/resources/web/require-js-cfg.js'></script>");
document.write("<script language='javascript' type='text/javascript' src='http://localhost:4200/pentaho/content/pentaho-cdf-dd/js/cde-require-js-cfg.js'></script>");
document.write("<script language='javascript' type='text/javascript' src='http://localhost:4200/pentaho/content/config/deploy/client-config-enabler-require-js-cfg.js'></script>");
document.write("<script language='javascript' type='text/javascript' src='http://localhost:4200/pentaho/content/common-ui/resources/web/common-ui-require-js-cfg.js'></script>");
document.write("<script language='javascript' type='text/javascript' src='http://localhost:4200/pentaho/content/pentaho-cdf/js/cdf-require-js-cfg.js'></script>");
document.write("<script language='javascript' type='text/javascript' src='http://localhost:4200/pentaho/js/require-js-cfg.js'></script>");
document.write("<script language='javascript' type='text/javascript' src='http://localhost:4200/pentaho/content/reporting/reportviewer/reporting-require-js-cfg.js'></script>");
document.write("<script language='javascript' type='text/javascript' src='http://localhost:4200/pentaho/content/common-ui/resources/web/require.js'></script>");
document.write("<script language='javascript' type='text/javascript' src='http://localhost:4200/pentaho/content/common-ui/resources/web/require-cfg.js'></script>");
requireCfg.config["pentaho/environment"] = {
theme: null,
locale: "en_US",
user: {
id: "admin",
home: "/home/admin"
},
server: {
root: "http://localhost:4200/pentaho/"
},
reservedChars: "\/\\\t\r\n"
};
/** @deprecated - use 'pentaho/environment' module's variable instead */
var CONTEXT_PATH = 'http://localhost:4200/pentaho/';
/** @deprecated - use 'pentaho/environment' module's variable instead */
var FULL_QUALIFIED_URL = 'http://localhost:4200/pentaho/';
/** @deprecated - use 'pentaho/environment' module's variable instead */
var SERVER_PROTOCOL = 'http';
/** @deprecated - use 'pentaho/environment' module's variable instead */
var SESSION_NAME = 'admin';
/** @deprecated - use 'pentaho/environment' module's variable instead */
var SESSION_LOCALE = 'en_US';
/** @deprecated - use 'pentaho/environment' module's variable instead */
var HOME_FOLDER = '/home/admin';
/** @deprecated - use 'pentaho/environment' module's variable instead */
var RESERVED_CHARS = '\/\\\t\r\n';
/** @deprecated - use 'pentaho/environment' module's variable instead */
var RESERVED_CHARS_DISPLAY = '\/, \\, \\t, \\r, \\n';
/** @deprecated - use 'pentaho/environment' module's variable instead */
var RESERVED_CHARS_REGEX_PATTERN = /.*[\/\\\t\r\n]+.*/;
document.write 是由 Pentaho 的脚本实例化的,所以我无法控制它,也无法修改脚本。
我尝试使用 postscribe 但问题仍然存在