KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Getting image tag source locations from a Web Area
PRODUCT: 4D | VERSION: 13.5 | PLATFORM: Mac & Win
Published On: September 18, 2014

Here is a snippet of code that can be used for getting all of the image tag source locations from a web page that is displayed in a Web Area:

C_TEXT($1;$WAObjName) // web area object name
C_POINTER($2) // pointer to text array for the source locations
C_LONGINT($numImgs;$a)

If (Count parameters=2)
   $WAObjName:=$1
   $numImgs:=WA Evaluate JavaScript(*;$WAObjName;"document.getElementsByTagName('img').length";Is longInt)
   ARRAY TEXT($2->;$numImgs) // size array accordingly
   For ($a;1;$numImgs)
      $js:="document.getElementsByTagName('img')["+String($a-1)+"].src"
      $2->{$a}:=WA Evaluate JavaScript(*;$WAObjName;$js;Is text)
   End for
End if


The code above should be saved in a project method named UTIL_getImgTagSources and then it can be used like this:
ARRAY TEXT($imgSrcTags_at;0)
UTIL_getImTagSources ("WABrowser";->$imgSrcTags_at)


After running the code above the $imgSrcTags_at text array would contain all of the source locations for the image tags found in the page that was loaded in the web area with an object named WABrowser.

Commented by Paul Medland on October 9, 2014 at 9:39 AM
The article indicates that this is for v13.5 but it is for v14.