That was the root of the problem. That was why I was messing around with cookies in an attempt to stop variables disappearing before I could use them.
This works: (Simple, small, and doesn't need cookies) /files/images.js:
// images.js
var JS_First_Image= "files/bomb.png", JS_Second_Image= "files/eye.png";
var First_Image_x_1, First_Image_y_1;
var Second_Image_x_1, Second_Image_y_1;
function init() {
// Write the first image invisibly.
document.getElementById("image_init_1").innerHTML= '<img id="First_one" alt="Move along" src="'+JS_First_Image+'" style="width:0px; height:0px;" onload="init_2()">';
}
function init_2() {
// When the first image has loaded, write the second image invisibly.
document.getElementById("image_init_2").innerHTML= '<img id="Second_one" alt="Nothing to see" src="'+JS_Second_Image+'" style="width:0px; height:0px;" onload="get_sizes()">';
}
function get_sizes() {
// When both images have loaded, get their dimensions.
First_Image_x_1= document.getElementById("First_one").naturalWidth;
First_Image_y_1= document.getElementById("First_one").naturalHeight;
Second_Image_x_1= document.getElementById("Second_one").naturalWidth;
Second_Image_y_1= document.getElementById("Second_one").naturalHeight;
document.getElementById("test1").innerHTML= "Image1: "+First_Image_x_1+" "+First_Image_y_1+" Image2: "+Second_Image_x_1+" "+Second_Image_y_1;
// Proceed from here.
}
Scope
Date: 2019-06-11 08:20 am (UTC)This works:
(Simple, small, and doesn't need cookies)
/files/images.js:
Output (for both FF & Chrome):
Image1: 49 50 Image2: 34 34