const iframe = document.createElement("iframe");
iframe.setAttribute("hidden","hidden");
document.body.appendChild(iframe);
iframe.onload = () => {
if(iframe){
iframe.setAttribute('src','about:blank');
}
};
let url = "xxx";
iframe.setAttribute("src",url);
上面是网上查到的解决办法,但没有解决问题,将代码修改为:
const iframe = document.createElement("iframe");
iframe.setAttribute("hidden", "hidden");
iframe.onload = () => {
if (iframe) {
console.log("iframe onload....")
iframe.setAttribute('src', 'about:blank');
}
};
document.body.insertBefore(iframe,null);
iframe.setAttribute("src", url);