2014-02-11 103 views
0

我遇到了firefox和innerhtml的问题。我想不通为什么它不工作:/铬,歌剧,IE,Safari浏览器工作正常,但Firefox ...Mozilla Firefox innerhtml无法正常工作

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<head> 
    <title>Dokument bez názvu</title> 
    <meta charset="utf-8"> 
    <link rel="stylesheet" type="text/css" href="css/styl.css"> 
    <script type='text/javascript' src='js/jquery-1.9.1.js'></script> 
    <style> 
     #displaybox 
     { 
      z-index: 10000; 
      filter: alpha(opacity=100); /*older IE*/ 
      filter: progid:DXImageTransform.Microsoft.Alpha(opacity=100); /* IE */ 
      -moz-opacity: 1; /*older Mozilla*/ 
      -khtml-opacity: 1; /*older Safari*/ 
      opacity: 1; /*supported by current Mozilla, Safari, and Opera*/ 
      position: fixed; 
      top: 20px; 
      left: 0px; 
      width: 100%; 
      height: 100%; 
      color: #FFFFFF; 
      text-align: center; 
      vertical-align: middle; 
     } 
     body 
     { 
      font-family: Calibri; 
     } 
     .black_overlay 
     { 
      visibility: hidden; 
      position: absolute; 
      top: 0%; 
      left: 0%; 
      width: 100%; 
      height: 100%; 
      background-color: black; 
      z-index: 1001; 
      -moz-opacity: 0.7; 
      opacity: .70; 
      filter: alpha(opacity=70); 
     } 
    </style> 
    <script> 
     function clicker() { 
      var thediv = document.getElementById('displaybox'); 
      if (thediv.style.display == "none") { 
       thediv.style.display = ""; 
       thediv.innerHTML = "<embed src='prohlidka.html' height='638' width='1024' ></embed>"; 
       var thelay = document.getElementById('fade'); 
       thelay.style.visibility = "visible"; 
      } else { 
       thediv.style.display = "none"; 
       thediv.innerHTML = ''; 
       var thelay = document.getElementById('fade'); 
       thelay.style.visibility = "hidden"; 
      } 
      return false; 
     } 

    </script> 
</head> 
<body> 
    <div id="fade" class="black_overlay"> 
    </div> 
    <div id="displaybox" style="display: none; overflow: visible"> 
    </div> 
    <a id="otevrit" href='#' onclick='return clicker();'>Virtuální mapa</a> 
</body> 

这是我的代码,CSS的一点点,一个功能和身体。正如我所说,其他浏览器工作正常。他们通常显示innerhtml正是我需要的。但Firefox并没有,黑色覆盖工作正常。没有错误,当我检查javascript时没有消息。

回答

0

您的代码在Mozilla Firefox中正常工作。

我用它在此琴:WORKING FIDDLE,只是添加了此行的代码: console.log($('#displaybox').html());和我得到的答案是: <embed src="https://www.google.com/" height="638" width="1024">,因为我已经提供了相同的输入这是正确的。

当我看到萤火虫中的编号为displaybox时,我能够看到embed代码被嵌入在该ID中。

因此,从技术上来说代码没有问题,如果您想要打开页面,那么您的logicwrong。您必须使用iframe src而不是embed来打开页面。

+0

我跑这个代码以及它工作正常。 – bergie3000

+0

我用iframe替换了嵌入,它工作正常:D非常感谢你。它也解决了我的其他问题^^ – user3197269

+0

@ user3197269:很高兴有帮助:) –

0

我不是innerhtml这个问题,它是<embed>标记。这并不意味着打开网页,但例如视频。您应该尝试使用类似的东西。

0

我遇到了同样的问题。解决方案是,您可以使用.value而不是.innerHTML从Div中获取值。这对于你将要使用的任何浏览器来说都会很蹩脚。