Poryhedron
10-30-2003, 05:23 PM
I have a gallery on my site that shows a couple dozen images per page. Each image also exists in a normal and a special version (for example, 001s.gif is a special version of 001.gif.) I want to set up the gallery so that every time you load a page, each image has a small random chance of appearing in its special version instead of its normal version. In addition, if the user's browser cannot handle JavaScript or is set to disallow it, the page needs to display the normal version (if I don't specifically allow for this, non-JS browsers end up displaying nothing, which isn't good...)
I have written code to achieve this effect, and it works exactly the way it should...in IE6 on WinXP. However, I have been informed that it does not function correctly in IE5.2 on Mac OS X; neither picture shows up.
I'm not really surprised that a Mac produces errors in my code, not because the system is bad in any way but because my experience with it is very limited. However, for Internet Explorer to mess it up is a bit surprising to me. The code, to my knowledge, should be compatible with IE and Netscape from v4 up, so I have no idea what's wrong.
Since I don't know the problem, I'm forced to give you the entire code, but it's not very long. Can anyone offer a solution, and maybe an explanation while you're at it?
First, the function itself...
<script type="text/javascript">
<!--
function shinycheck(IDnum) {
var shinerate = 10;
// Change the number above to change the rate of Shiny appearances.
// Each pic has a 1-in-shinerate chance of being shiny; default is 1 in 10, or 10%.
var shinevalue = Math.floor(Math.random()*shinerate);
if (shinevalue == 0) {
document.write("<img src=" + IDnum + "s.gif>");
} else {
document.write("<img src=" + IDnum + ".gif>");
}
}
// -->
</script>
...and an example of a function call in the body of the page.
<th colspan=2>
<script type="text.javascript">
<!--
shinycheck("001");
// -->
</script>
<noscript><img src=001.gif></noscript>
</th>
/added later/ All right, I just now noticed the typo in the function call while reviewing my post. Would the period instead of a forward slash cause it fail in Mac IE5.2 while still working on WinXP IE6?
I have written code to achieve this effect, and it works exactly the way it should...in IE6 on WinXP. However, I have been informed that it does not function correctly in IE5.2 on Mac OS X; neither picture shows up.
I'm not really surprised that a Mac produces errors in my code, not because the system is bad in any way but because my experience with it is very limited. However, for Internet Explorer to mess it up is a bit surprising to me. The code, to my knowledge, should be compatible with IE and Netscape from v4 up, so I have no idea what's wrong.
Since I don't know the problem, I'm forced to give you the entire code, but it's not very long. Can anyone offer a solution, and maybe an explanation while you're at it?
First, the function itself...
<script type="text/javascript">
<!--
function shinycheck(IDnum) {
var shinerate = 10;
// Change the number above to change the rate of Shiny appearances.
// Each pic has a 1-in-shinerate chance of being shiny; default is 1 in 10, or 10%.
var shinevalue = Math.floor(Math.random()*shinerate);
if (shinevalue == 0) {
document.write("<img src=" + IDnum + "s.gif>");
} else {
document.write("<img src=" + IDnum + ".gif>");
}
}
// -->
</script>
...and an example of a function call in the body of the page.
<th colspan=2>
<script type="text.javascript">
<!--
shinycheck("001");
// -->
</script>
<noscript><img src=001.gif></noscript>
</th>
/added later/ All right, I just now noticed the typo in the function call while reviewing my post. Would the period instead of a forward slash cause it fail in Mac IE5.2 while still working on WinXP IE6?