I’m trying to automate the process of pop-up windows so have (attempted) to write a script to do this for me.
Basically it loops through all the links on the page with a certain class name then looks what file type it’s opening. My problem stems from trying to get the new window to fit the size of an image that won’t have previously loaded in to the browser.
At the moment I cannot get it to alert the width of the image and obviously the sticking point is at the newImage.onload stage.
I would appreciate it if you could have a quick look and point me in the right direction – or explain if I have coded it badly
[CODE]function getDimentions() {
alert(this.width);
}
function popUp() {
var links=document.getElementsByTagName(“a”);
for(var i=0; i<links.length; i++) {
if(links[i].className==”pop_up”) {
links[i].onclick=function() {
var image_location=”../”+this.getAttribute(“href”);
var newImage=new Image();
newImage.src=image_location;
newImage.onload=getDimentions;
return false;
}
}
}
}