how to get swf/image width/height with javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Kypriotis
    New Member
    • Mar 2011
    • 37

    how to get swf/image width/height with javascript

    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)
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    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.

    Comment

    • Mike Kypriotis
      New Member
      • Mar 2011
      • 37

      #3
      height/width properties also work, problem is I want to do the same with swf files and do not work for images I use
      Code:
      var img = new Image();
      is there something more generic than Image() like object() which can accept swf?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        If I remeber right, an SWF file is used with the <object> tag, i.e. document.create Element("object ");

        Comment

        • Mike Kypriotis
          New Member
          • Mar 2011
          • 37

          #5
          in the new Image() way of thinking tried
          Code:
          var a=document.createElement("object"); 
          a.src="test.swf";
          var height = a.height;
          var width = a.width;
          alert ('The swf size is '+width+'*'+height);
          hoping that once the src was set I could retrieve the dimension but didn't worked

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            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)

            Comment

            Working...