我想在我的java项目中使用Karspersky小部件,但我没有在java中运行html代码。我试图只运行js,但我收到一个错误:
引起:
<eval>:31
ReferenceError :“文档”未定义
我该怎么办?
public class MainClass {
public static void main(String[] args) {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
try {
FileReader reader = new FileReader("/home/havelsan/Desktop/widget.js");
engine.eval(reader);
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
widget.js
// Cybermap v2 widget loader
(function() {
function setup_widget(div) {
var config = {
width: div.dataset.width || 640,
height: div.dataset.height || 640,
language: div.dataset.language || 'en',
theme: div.dataset.theme || 'dark',
type: div.dataset.type || 'dynamic'
};
console.log("config.language >> " + config.language);
var iframe = document.createElement('iframe');
var baseURI = 'https://cybermap.kaspersky.com/';
iframe.src = baseURI + (config.type == 'dynamic' ? 'widget.html' : 'widget-static.html');
iframe.style.width = config.width + 'px';
iframe.style.height = config.height + 'px';
iframe.style.border = 'none';
iframe.onload = function() {
console.log("config.language >> " + config.language);
var msg = JSON.stringify({ config: config });
iframe.contentWindow.postMessage(msg, '*');
};
console.log("config.language >> " + config.language);
div.appendChild(iframe);
}
var divs = document.querySelectorAll('.kas-cybermap-widget');
for (var i = 0; i < divs.length; ++i) {
setup_widget(divs[i]);
}
}());