Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript IE 8 iframe边框_Javascript_Html_Css_Iframe_Internet Explorer 8 - Fatal编程技术网

Javascript IE 8 iframe边框

Javascript IE 8 iframe边框,javascript,html,css,iframe,internet-explorer-8,Javascript,Html,Css,Iframe,Internet Explorer 8,iframe上显示了一个边框,我无法摆脱它 IE 6和7使用少量JavaScript即可正常工作: 功能测试(){ var iframe=document.getElementById('frame2'); iframe.contentWindow.document.body.style.backgroundColor=“#A31D”; iframe.contentWindow.document.body.style.border=“#a31dd”; iframe.contentWindow.d

iframe
上显示了一个边框,我无法摆脱它

IE 6和7使用少量JavaScript即可正常工作:

功能测试(){
var iframe=document.getElementById('frame2');
iframe.contentWindow.document.body.style.backgroundColor=“#A31D”;
iframe.contentWindow.document.body.style.border=“#a31dd”;
iframe.contentWindow.document.body.style.outlineColor=“#A31D”;
}

但是边框在IE 8中仍然可见。

与示例JS一起使用的示例HTML将很有帮助=)


尝试使用IE8的开发工具(在有问题的页面上按F12键)来隔离iframe应用的样式。您还可以在那里使用样式,以缩短迭代时间。

请记住,这可能是因为IE不考虑css中的边框设置,而iframe元素上属性
border=0的传统设置可能会起作用。至少值得一试


编辑:似乎解决问题的方法是在iframe元素上设置frameborder='0'。至少对我来说是这样。

在iframe标记中添加以下属性:

marginheight="0" marginwidth="0" frameborder="0"

我对动态创建的iframe也有同样的问题,结果是在将iframe添加到文档后设置边框属性,没有效果:

以下代码显示三维边框:

var iframe = document.createElement("IFRAME");
iframe.src = "http:www.stackoverflow.com";
//Iframe added BEFORE setting border properties.
document.body.appendChild(iframe);
iframe.frameBorder = "no";
但这实际上消除了它:

var iframe = document.createElement("IFRAME");
iframe.src = "http:www.stackoverflow.com";
iframe.frameBorder = "no";
//Iframe added AFTER setting border properties.
document.body.appendChild(iframe);

希望这有助于解决您的问题。

我尝试了大量关于这个想法的变化,最终使用了类似的方法。我想和你分享一下

<script type="text/javascript">
   url = 'http://www.dollypower.com';
   title = 'Dolly Power';
   width = '660';
   height = '430';
    document.write('<iframe src='+url+' title='+title+' width='+width+' height='+height+' frameborder=0></iframe>');
 </script>

url='1〕http://www.dollypower.com';
标题=‘小车动力’;
宽度='660';
高度='430';
文件。写(“”);
然后,我使用noscript标记为非JS用户输入一个替代项,即:

<noscript><p><a href="http://www.dollypower.com" target="_blank">Please click here for Dolly Power</a></p></noscript>

我在IE8中测试了它,它对我来说很酷,并且也验证了它

希望这能帮助别人

成功

试试这个。它将在IE和其他浏览器中查找任何iframe元素并删除它们的边框(尽管您可以在非IE浏览器中设置“border:none;”样式,而不使用JavaScript)。即使在生成iframe并将其放在文档中(例如,以纯HTML而非JavaScript添加的iframe)之后使用,它也可以工作

这似乎是可行的,因为IE在BOM中创建iframe之后,不是在iframe元素上创建边框,而是在iframe的内容上创建边框。($@&*#@!!!IE!!!)

注意:如果父窗口和iframe来自同一来源(相同的域、端口、协议等),IE部分将(当然)工作。否则,脚本将在IE错误控制台中获得“拒绝访问”错误。如果发生这种情况,您唯一的选择就是在生成它之前设置它,正如其他人所指出的,或者使用非标准的frameBorder=“0”属性。(或者让IE看起来很漂亮——我目前最喜欢的选择;)

我花了好几个小时工作到绝望的地步才弄明白

享受。:)

//=========================================================================
//删除iFrame上的边框
if(window.document.getElementsByTagName(“iframe”))
{
var iframelements=window.document.getElementsByTagName(“iframe”);
对于(var i=0;i
如果希望代码验证,可以使用javascript进行验证。几个月前,当我遇到这个问题时,我找到了完美的答案

如果希望在iframe中无缝加载另一个页面,则可以将此代码复制并粘贴到页面头部。我在一个有免费脚本的网站上找到了它。在大多数情况下,性能良好

function getDocHeight(doc) {
    doc = doc || document;
    var body = doc.body, html = doc.documentElement;
    var height = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight );
    return height;
}
function setIframeHeight(id) {
    var ifrm = document.getElementById(id);
    var doc = ifrm.contentDocument? ifrm.contentDocument: ifrm.contentWindow.document;
    ifrm.style.visibility = 'hidden';
    ifrm.style.height = "10px"; // reset to minimal height in case going from longer to shorter doc
    ifrm.style.height = getDocHeight( doc ) + 10 + "px";
    ifrm.style.visibility = 'visible';
}
然后给iframe一个id,并在加载时调用脚本。这就是为什么

var iframe = document.createElement("iframe");
 iframe.setAttribute('id', "ifrm1");
 iframe.setAttribute('src', 'http://www.hekcmviw.com/'); // change the URL
 iframe.setAttribute('width', '100%');
 iframe.setAttribute('height', '10');
 iframe.setAttribute('frameBorder', '0');
 iframe.setAttribute('scrolling', 'no');
 iframe.setAttribute('onload' ,"setIframeHeight(this.id)");
 document.body.appendChild(iframe);

StackOverflow在输入问题的文本区域下方有一个很棒的预览区域。下一次发布之前,使用该预览修复格式。我尝试使用jQuery实用地添加这些内容,但IE8似乎只是忽略了它们;在浪费了太多时间试图隐藏一个边界(这是一个多么琐碎的任务啊?)之后,我使用了硬编码属性来强制IE8实现这一点。“为什么IE如此垃圾!?”是我今天最喜欢的一句话——是的,我正在进行跨浏览器测试:-D.呵呵。谢谢你弄明白了!仅供参考:不幸的是,在文档中内联添加frameborder属性将使文档永远无法验证HTML 5。但是似乎没有其他方法可以解决这个问题。frameborder=“0”在IE8上从iframe中删除了边框是的,这很有意义。。。添加三个我一生中从未使用过的html属性。谢谢IE8中仍然有一条黑线
function getDocHeight(doc) {
    doc = doc || document;
    var body = doc.body, html = doc.documentElement;
    var height = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight );
    return height;
}
function setIframeHeight(id) {
    var ifrm = document.getElementById(id);
    var doc = ifrm.contentDocument? ifrm.contentDocument: ifrm.contentWindow.document;
    ifrm.style.visibility = 'hidden';
    ifrm.style.height = "10px"; // reset to minimal height in case going from longer to shorter doc
    ifrm.style.height = getDocHeight( doc ) + 10 + "px";
    ifrm.style.visibility = 'visible';
}
var iframe = document.createElement("iframe");
 iframe.setAttribute('id', "ifrm1");
 iframe.setAttribute('src', 'http://www.hekcmviw.com/'); // change the URL
 iframe.setAttribute('width', '100%');
 iframe.setAttribute('height', '10');
 iframe.setAttribute('frameBorder', '0');
 iframe.setAttribute('scrolling', 'no');
 iframe.setAttribute('onload' ,"setIframeHeight(this.id)");
 document.body.appendChild(iframe);