/    Sign up×
Community /Pin to ProfileBookmark

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;
}

}

}

}[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisJan 16.2007 — var image_location="../"+this.getAttribute("href");[/quote]Is this really where the image is? I suspect it is not, and so the image is "error".

There is an onerror event that will fire if the image doesn't exist where you think it is. Try adding an alert to prove that is what is happening.
Copy linkTweet thisAlerts:
@sinciliteauthorJan 16.2007 — Oh *expletive* that's it thanks!
×

Success!

Help @sincilite spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...