/    Sign up×
Community /Pin to ProfileBookmark

Safari conflict wit Width and Height

Can anyone tell me why Safari isn’t finding the width and height of my image.

External Javascript:

[CODE]
function cmdOpenWindow(image,subfolder){
var img = new Image();
var imgPath = “../Images/”;
if(subfolder!=””){
imgPath = imgPath + subfolder + “/” + image;
}
else{
imgPath = imgPath + image;
}
img.src = imgPath;
var width = [COLOR=”Red”]img.width[/COLOR] + 70;
var height = [COLOR=”red”]img.height [/COLOR]+ 90;
window.open(“/Pages/Images.asp?strImage=”+image+”&strSubfolder=”+subfolder, “_blank”, “toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=”+width+”, height=”+height);
}
[/CODE]

HTML:

[CODE]
<img class=”ImageOpen” src=”../Images/Folder1/tTheTeam.jpg” alt=”” height=”54″ width=”72″ border=”0″ onclick=”cmdOpenWindow(‘TheTeam.jpg’,’Folder1′)” />
[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Arty_EffemSep 08.2007 — Can anyone tell me why Safari isn't finding the width and height of my image.
[/QUOTE]
Because the image hasn't loaded at the time it's dimensions are being read. You need to use the image's onload event, either to trigger the reading of its dimensions or to set a flag that indicates that they can be read.
Copy linkTweet thisAlerts:
@nbcrockettauthorSep 08.2007 — How would you trigger the image's onload event so that it would be able to retreive those dimensions?
×

Success!

Help @nbcrockett 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 7.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ,
analytics: Fullres
});

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: @qewfun,
tipped: live stream
amount: 5000 SATS,

tipper: @qewfun,
tipped: live stream
amount: 5000 SATS,

tipper: @qewfun,
tipped: live stream
amount: 5000 SATS,
)...