codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Firefox/IE doctype problem.  greppinfunk at 12:00 on Thursday, September 27, 2007
 

Hi guys,

I'm having trouble with a effect I'm trying to produce, making a box change size overtime using setInterval.

The example code;


<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>

<style type="text/css">
body{padding:0px;margin:0px;margin:auto;}
#box{margin:100px auto;width:400px;height:100px;border:1px solid red;text-align:center;padding:50px;}
</style>

<script type="text/javascript">
steps = 2;
oInterval = "";

function changeMainBoxWidth(oldHeight,newHeight){
oInterval = window.setInterval(
function(){
oldHeight=oldHeight-steps;
if(oldHeight==newHeight)window.clearInterval(oInterval);
document.getElementById("box").style.height = oldHeight;
},steps);
}
</script>
<BODY>

<div id="box">
<a href="#" onClick="changeMainBoxWidth(100,10);">make me small</a>
</div>

</BODY>
</HTML>


Now the problem is the doctype if I use a strict doctype;

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">


The effect renders in IE perfectly, however it doesn't work in Firefox, if I use a loose or no doctype, so effectively rendering in quirks mode Firefox works perfectly but IE doesn't;

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


Is there anyway to get a middle ground without writing browser detection and forcing a doctype?




  Re: Firefox/IE doctype problem.  greppinfunk at 14:33 on Thursday, September 27, 2007
 

Ok I know no one else has replied to this, but I was delving into some sites, and found lots of information about how under a strict doctype Firefox doesn't render Javascript properly. I've got the point where I can extract the current width, but still Firefox refuses to render the height change.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>

<style type="text/css">
body{padding:0px;margin:0px;margin:auto;}
#box{margin:100px auto;width:400px;height:100px;border:1px solid red;text-align:center;padding:50px;}
</style>

<script type="text/javascript">
frameRate = 10;
oInterval = "";
currHeight = 0;
newHeight = 0;

//returns a property value in IE and NS6 Format
function getProperty(el, cssproperty, csspropertyNS){
if (el.currentStyle)
return el.currentStyle[cssproperty]
else if (window.getComputedStyle){
var elstyle=window.getComputedStyle(el, "")
return elstyle.getPropertyValue(csspropertyNS)
}
}

function changeMainBoxWidth(nH){
newHight = nH;
currHeightString = getProperty(document.getElementById("box"),"height","height");
currHeight = parseInt(currHeightString.split("p")[0]);
alert(currHeight);
oInterval = self.setInterval("animate()",frameRate);
}

function animate(){
currHeight--;
if(currHeight==newHeight){
window.clearInterval(oInterval);
}else{
document.getElementById("box").style.height = currHeight;
}
}

</script>
<BODY>

<div id="box">
<a href="#" onClick="changeMainBoxWidth(10);">make me small</a>
</div>

</BODY>
</HTML>


  Re: Firefox/IE doctype problem.  greppinfunk at 14:50 on Thursday, September 27, 2007
 

Ok although no one helped me I found a solution, and it works in both IE and Firefox using strict xhtml;


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>

<style type="text/css">
body{padding:0px;margin:0px;margin:auto;}
#box{margin:100px auto;width:400px;height:100px;border:1px solid red;text-align:center;padding:50px;}
</style>

<script type="text/javascript">
frameRate = 10;
oInterval = "";
currHeight = 0;
newHeight = 0;


//returns a property value in IE and NS6 Format
function getProperty(el, cssproperty, csspropertyNS){
if (el.currentStyle)
return el.currentStyle[cssproperty]
else if (window.getComputedStyle){
var elstyle=window.getComputedStyle(el, "")
return elstyle.getPropertyValue(csspropertyNS)
}
}

function changeMainBoxWidth(nH){
newHight = nH;
currHeightString = getProperty(document.getElementById("box"),"height","height");
currHeight = parseInt(currHeightString.split("p")[0]);
alert(currHeight);
oInterval = self.setInterval("animate()",frameRate);
}

function animate(){
currHeight--;
if(currHeight==newHeight){
window.clearInterval(oInterval);
}else{
document.getElementById("box").style.height = currHeight + "px";
}
}

</script>
<BODY>

<div id="box">
<a href="#" onClick="changeMainBoxWidth(10);">make me small</a>
</div>

</BODY>
</HTML>


The problems that arose, was because when IE and Firefox are in strict mode, style declaration setting and getting elements is vastly different from the loose modes. Also it needed "px" at the end of currHeight for it to work at Firefox.

Hope this helps someone, as it took me ages to find this out.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  array of struct
•  matrix prblm in java
•  Re: how to open instantly a pop up window whenever a user sends a message to the other user
•  Re: PING PROGRAM IN PERL
•  Re: date of birth validation using java script-very urgent
•  JAVA If statements
•  Need Help with a Regular Expression
•  Informations on HTML
•  Re: FREE TV on your PC!


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010