简体   繁体   中英

Image size not defined in Javascript / PHP

I'm having problems finding the width and height of an image. I'm trying to pass it to the URL so I can set it as a PHP session variable.

location.href="homeview.php?x=" + dd.elements.image1.x + "&y=" + dd.elements.image1.y + "&h=" + document.getElementById('image1').height;

the URL reads as such with an example image:

homeview.php?x=8&y=8&h=undefined

so I've tried

location.href="homeview.php?x=" + dd.elements.image1.x + "&y=" + dd.elements.image1.y + "&h=" + dd.elements.image1.height;

and its still undefined, my img tags are like this

<img id="image1" src="newimages/image1.png" width="45" height="45">

If it helps, the Javascript is run in a function at the bottom of the page. Any advice would help.

Thank you guys!!

try

document.getElementById('image1').offsetHeight;

https://developer.mozilla.org/en/DOM/element.offsetHeight

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM