现在有一段动态获取的前端代码,想要放到页面中去加载。
那么使用 iframe 然后 write 内容,还是直接在页面 append 一个元素?
这两种方式哪种比较好?各有什么利弊??
使用 iframe
iframe = document.createElement('iframe');
iframe.setAttribute('frameborder', '0');
iframe.setAttribute('id', '123');
iframe.setAttribute('width', '100%');
iframe.setAttribute('height', '100%');
document.getElementById("templateBody").appendChild(iframe);
iframe.contentDocument.open();
iframe.contentDocument.write(value);
iframe.contentDocument.close();
append 到页面
$('#templateBody').html(value);