Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by garysamuels
at 2024-07-25 08:09:24
Point:500 Replies:2 POST_ID:829105USER_ID:10
Topic:
JavaScript;jQuery;Hypertext Markup Language (HTML)
I need to know the width of an image before it is called in the html source. I know the name of the image and I'm trying to use javascript to discover the width. This returns a vale of 0 for the width.
var img = new Image();
img.src = "http://mysite.com/graphics/myimage.png"
window.confirm(img.width);
var img = new Image();
img.src = "http://mysite.com/graphics/myimage.png"
window.confirm(img.width);
Accepted Solution
Expert: duncanb7 replied at 2024-07-25 08:37:54
250 points EXCELLENT
You can do get the image width before adding it into DOM
Duncan
Duncan
<script type="text/javascript">var getImageSize = function(src) { var img = new Image(); $(img).bind('load', function(e) { var height = img.height; var width = img.width; // document.write('width:' + width + ', height: ' + height); alert("width="+width); }); img.src = src;};getImageSize('http://localhost/data/php/water.jpg');</script> 1:2:3:4:5:6:7:8:9:10:11:12:13:
Assisted Solution
Expert: Randy Poole replied at 2024-07-25 08:22:09
250 points EXCELLENT
There is no way to know before it is loaded. You can however catch this info before you add it to your page and do what needs to be done:
img = new Image();img.onload = function() { alert("(" + this.width + "x" + this.height+")");};img.src = "http://mysite.com/graphics/myimage.png"; 1:2:3:4:5: