在动态加载的 iframe 中设置样式
set style in dynamically loaded iframe
我要转换:
<iframe src="http://www.example.com" width="0" height="0" style="visibility:hidden;display:none"></iframe>
使用 javascript 动态加载它,目前我的代码是:
var iframe = document.createElement('iframe');
iframe.src = 'http://www.example.com';
iframe.width = '0';
iframe.height = '0';
document.body.appendChild(iframe);
但是一旦加载,就会看到一个小框,我尝试添加:
iframe.style = 'visibility:hidden;display:none';
但这没有效果,有谁知道如何做到这一点(没有 JQuery)?
谢谢
您必须将边框设置为 0:
var iframe = document.createElement('iframe');
iframe.src = 'http://www.example.com';
iframe.width = '0';
iframe.height = '0';
iframe.frameBorder = '0'; // Add this line
document.body.appendChild(iframe);
我要转换:
<iframe src="http://www.example.com" width="0" height="0" style="visibility:hidden;display:none"></iframe>
使用 javascript 动态加载它,目前我的代码是:
var iframe = document.createElement('iframe');
iframe.src = 'http://www.example.com';
iframe.width = '0';
iframe.height = '0';
document.body.appendChild(iframe);
但是一旦加载,就会看到一个小框,我尝试添加:
iframe.style = 'visibility:hidden;display:none';
但这没有效果,有谁知道如何做到这一点(没有 JQuery)? 谢谢
您必须将边框设置为 0:
var iframe = document.createElement('iframe');
iframe.src = 'http://www.example.com';
iframe.width = '0';
iframe.height = '0';
iframe.frameBorder = '0'; // Add this line
document.body.appendChild(iframe);