2 回答
TA贡献1829条经验 获得超7个赞
这似乎按预期工作:
const script = document.createElement('script');
script.src = 'data:text/html,id = 0;while(true){ if(++id==1000000) break;} window.test = 1; console.log("test defined.");';
script.onload = () => console.log('onload called.', window.test);
document.body.appendChild(script);
TA贡献1880条经验 获得超4个赞
尝试这个:
const injectScript = () => {
const script = document.createElement('script');
script.innerHTML = 'console.log("Function loaded..."); window.postMessage({cmd:"loaded"});';
script.async = false;
document.body.appendChild(script);
}
setTimeout(injectScript, 3000);
window.addEventListener('message', function(e){
if(e.data.cmd === 'loaded'){
console.log('external library loaded');
}
});
- 2 回答
- 0 关注
- 127 浏览
添加回答
举报