FileMaker: Detecting Web Viewer Image Load

In FileMaker you can load content in web viewer boxes. While useful, they load at a different pace than the rest of the record they are in. For detecting the load of an image in a web viewer I use the following code.

Before getting into the script details, we need to ensure that our layout is ready. For this script to work we need add a name to our web viewer object. In my layout it is simply labeled ‘webviewer’, but it can be whatever you want. The name is required so we can use the GetLayoutObjectAttribute function.

The following script will loop until an image in the web viewer object is loaded:

Set Variable [ $i; Value:0 ]
  Exit Loop If [ 
  GetLayoutObjectAttribute ( "webviewer" ; "content" ) ≠ "" or
  PRODUCTS::ImageURL = "" or
  ( GetLayoutObjectAttribute ( "webviewer" ; "content" ) = "" and $i > 100 ) or
  $i > 500 ]
  Pause/Resume Script [ Duration (seconds): .01 ] Set Variable [ $i; Value:$i + 1 ]
End Loop

When the content of the image isn’t loaded, the GetLayoutObjectAttribute function returns nothing (a null value), unlike a website. However, when an image has been loaded in the web viewer the “content” can’t actually be gotten with this function and it will return an error. However, this error is enough to know that the image is loaded.

In the code above, if the ImageURL field (used by the web viewer) is empty, it will skip the loop. Also, there are also two time-out checks, just in case, so we don’t get stuck in an unexpected, out-of control loop.

Leave a Reply

Your email address will not be published. Required fields are marked *