2010-11-18 33 views
0

Burada IE için iyi çalışan ancak FireFox'ta düzgün çalışmıyor olan javascript'i veriyorum. öyleyse lütfen benim javascript'imde neyi değiştireceğimi de söyle lütfen.javascript çapraz tarayıcı çözümü gerekir?

burada benim kod

<html xmlns="http://www.w3.org/1999/xhtml" > 
    <head id="Head1" runat="server"> 
     <title>Untitled Page</title> 
     <script type="text/javascript" language="javascript"> 

      var modalWindow = null; 
      function drawDiv() 
      { 
       var txt = document.getElementById('TextBox1'); 
       var dime = new Dimension(txt); 
       modalWindow = document.createElement('div'); 
       modalWindow.style.position = 'absolute'; 
       modalWindow.setAttribute("align", "center"); 
       modalWindow.setAttribute("vertical-align", "middle"); 
       modalWindow.innerHTML = '<p>hello...</p>'; 
       modalWindow.style.left = dime.x; 
       modalWindow.style.top = dime.y; 
       modalWindow.style.width = dime.w; 
       modalWindow.style.height = dime.h; 
       modalWindow.style.backgroundColor = '#C0C0C0'; 
       document.body.appendChild(modalWindow); 
       return false; 
      } 

      function hider(whichDiv) 
      { 
       document.getElementById(modalWindow).style.display = 'none'; 
      } 

      function Dimension(element) 
      { 
       this.x = -1; 
       this.y = -1; 
       this.w = 0; 
       this.h = 0; 
       if (element == document) 
       { 
        this.x = element.body.scrollLeft; 
        this.y = element.body.scrollTop; 
        this.w = element.body.clientWidth; 
        this.h = element.body.clientHeight; 
       } 
       else if (element != null) 
       { 
        var e = element; 
        var left = e.offsetLeft; 
        while ((e = e.offsetParent) != null) 
        { 
         left += e.offsetLeft; 
        } 
        var e = element; 
        var top = e.offsetTop; 
        while ((e = e.offsetParent) != null) 
        { 
         top += e.offsetTop; 
        } 
        this.x = left; 
        this.y = top; 
        this.w = element.offsetWidth; 
        this.h = element.offsetHeight; 
       } 
      } 
     </script> 
    </head> 
    <body> 
<div> 
<form id="form1" runat="server"> 

    <asp:TextBox ID="TextBox1" runat="server" Height="180px" Style="left: 307px; position: relative; 
     top: 264px" TextMode="MultiLine" Width="432px"></asp:TextBox> 
    <asp:Button ID="Button1" runat="server" 
     Text="Button" OnClientClick=" return drawDiv()" /> 
</form> 
</div> 
</body> 
</html> 
+0

Aaah anlayamazlar boyutlar sonra "px" koymak demek olduğunu! Gözlerim kanıyor! Doğru kod formatını kullanmayı düşünür müsün lütfen? Teşekkürler. :) – Alex

+0

[JSBeautifier.org] adresine gidin (http://jsbeautifier.org/) ve kodunuzu siteden düzgün bir şekilde biçimlendirilmiş çıktıyla güncelleyin. Lütfen? – xj9

+0

Muhtemel davranışı ve gerçek _problem_ hakkında olabildiğince fazla bilgi açıklayabilir misiniz? Örneğin. "Kutu mükemmel kare değil" veya "Düğmeyi tıkladığımda hiçbir şey olmuyor". – ken

cevap

1

kullanım

  modalWindow.style.left = dime.x + "px"; 
      modalWindow.style.top = dime.y + "px"; 
      modalWindow.style.width = dime.w + "px"; 
      modalWindow.style.height = dime.h + "px"; 

i .. aksi firefox sizin birim türü :))

+0

Cevabınız için teşekkürler. Sorunumu çözmek için bu kodu deneyeceğim. – Thomas

İlgili konular