Created
May 21, 2020 23:17
-
-
Save luisenriquecorona/a797e36ced3bbc3554f14ba32f75c11b to your computer and use it in GitHub Desktop.
A smarter scripter would recognize that the preceding scripts might fail in very old browsers, where script errors tend to be rather invasive. To prevent such errors, the author makes two modifications. First, the potentially offending script statements in the getImgAreas( ) function wrap themselves in an object detection block. Second, the main…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getImgAreas( ) { | |
var result; | |
// make sure browser supports img element objects | |
if (document.images) { | |
// initialize return value so we can add to it | |
result = 0; | |
// loop through all img objects on the page | |
for (var i = 0; i < document.images.length; i++) { | |
// accumulate image areas | |
result += (document.images[i].width * document.images[i].height); | |
} | |
} | |
// returned value is either a number or null | |
return result; | |
} | |
function reportImageArea( ) { | |
// grab result so we can verify it | |
var imgArea = getImgAreas( ); | |
var output; | |
if (imgArea == null) { | |
// message for browsers not supporting img object | |
output = "Unknown"; | |
} else { | |
output = imgArea; | |
} | |
document.reportForm.imgData.value = output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment