PDA

View Full Version : Image resizer script - only works in IE



techno_race
03-14-2010, 03:08 AM
I wrote a script to resize some images to be a percentage of the window width, but it only works in Internet Explorer. (I've tested IE, Firefox, and Chrome, but not Opera, Safari, or whatever else people are using these days.)


...
<head>
...
<title>...</title>
<script type="text/javascript">
<!--
function MM_swapImgRestore() { //v3.0
...
}
function MM_preloadImages() { //v3.0
...
}

function MM_findObj(n, d) { //v4.01
...
}

function MM_swapImage() { //v3.0
...
}

// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// you may copy these functions but please keep the copyright notice as well
function pageWidth() {...} function pageHeight() {...} ...

var OldHeights;
var OldWidths;
var Backgrounds;
var NewWidths;
var i;
var available;
function ResizeImages() {
OldHeights = new Array(300,284,300,300,300,300,213,239,300);
OldWidths = new Array(210,300,283,263,218,272,300,300,278);
Backgrounds = new Array(1,0,0,1,0,0,1,0,0);
NewWidths = new Array(100,100,100,100,100,100,100,100,100);
i = 0;
available = pageWidth();
if (pageWidth() < 2524) {
while (i < 9) {
NewWidths[i] = pageWidth() * .066;
document.getElementById('image'+i).width = (NewWidths[i]);
if (Backgrounds[i] == 1) {
document.getElementById('back'+i).height = ((NewWidths[i]) / (OldWidths[i])) * (OldHeights[i]);
}
i++;
}
}
}
window.onresize = ResizeImages;
//-->
</script>
...
</head>

<body onload="ResizeImages();MM_preloadImages(...)">
...