我正在尝试动态插入以下内容:
var downloadJsOnLoad = function () {
var shareThisOne = document.createElement('script');
shareThisOne.text = 'var switchTo5x=true;';
document.body.appendChild(shareThisOne);
var shareThisTwo = document.createElement('script');
shareThisTwo.src = 'http://w.sharethis.com/button/buttons.js';
document.body.appendChild(shareThisTwo);
var text = 'stLight.options({publisher: "a8cae9ce-ebee-4346-9891-a1bfb0aa7005"});';
var shareThisThree = document.createElement('script');
shareThisThree.innerHTML = text;
document.body.appendChild(shareThisThree);
}
jQuery(window).load(function () {
downloadJsOnLoad();
});
一切正常,但是当解析此 javascript 时出现错误,提示 stLight 未定义。我假设它将 stLight.options 方法视为可执行文件而不是纯字符串。我怎样才能解决这个问题以避免错误?