getScript or eval in specific location?

放肆的年华 提交于 2019-12-01 11:24:44

Does the "JavaScript toolkit" you refer to use document.write or document.writeln to insert output into the page? If so, you could override that function to append the script output into the correct location:

document.write = function(s) {
    $('#fig').append(s);
};

document.writeln = function(s) {
    $('#fig').append(s + '\n');
};

and then load and execute the script using $.getScript.

Edit: A more robust way of doing it, depending on how the code is added:

var output = '';

document.write = function(s) {
    output += s;
};

document.writeln = function(s) {
    output += s + '\n';
};

$.getScript('URL of script here', function() {
    $('#fig').append(output);
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!