By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,473 Members | 1,278 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,473 IT Pros & Developers. It's quick & easy.

how to get swf/image width/height with javascript

Mike Kypriotis
P: 37
in php with getimagesize() for both img and swf worked well,in javascript?
PS I do not want to first load it and then use its id as a reference object, I want to know because I need to know in order to display it, (so use say the relative path as an argument to whatever works)
Apr 26 '11 #1
Share this Question
Share on Google+
5 Replies


Dormilich
Expert Mod 5K+
P: 8,639
you can’t determine an image’s size without downloading it. You may of course load it in the background without attaching it to the document tree.

To get the size of the image you can then use the naturalWidth/naturalHeight property of the image object, although that is not supported in every browser.
Apr 27 '11 #2

Mike Kypriotis
P: 37
height/width properties also work, problem is I want to do the same with swf files and do not work for images I use
Expand|Select|Wrap|Line Numbers
  1. var img = new Image();
is there something more generic than Image() like object() which can accept swf?
Apr 27 '11 #3

Dormilich
Expert Mod 5K+
P: 8,639
If I remeber right, an SWF file is used with the <object> tag, i.e. document.createElement("object");
Apr 27 '11 #4

Mike Kypriotis
P: 37
in the new Image() way of thinking tried
Expand|Select|Wrap|Line Numbers
  1. var a=document.createElement("object"); 
  2. a.src="test.swf";
  3. var height = a.height;
  4. var width = a.width;
  5. alert ('The swf size is '+width+'*'+height);
  6.  
hoping that once the src was set I could retrieve the dimension but didn't worked
Apr 27 '11 #5

Dormilich
Expert Mod 5K+
P: 8,639
hoping that once the src was set I could retrieve the dimension but didn't worked
obviously, the <object> element does not have a src attribute (an <object>ís source is defined in one of its <param> child elements)
Apr 27 '11 #6

Post your reply

Sign in to post your reply or Sign up for a free account.