Testing for a valid license

If a license is referenced, but fails to validate for some reason - for example, if the domain of the document is not listed in the license or the license has expired - then an error will be raised if a licensed method or property is accessed.

It should be noted that the user will have seen and dismissed an error dialog about the failure to validate the license. They may still continue on and trigger script that attempts to call licensed methods or properties.

There are three approaches:

  • Let the language runtime deal with the error. For server side use, the server side code will stop executing and the thrown error dealt with at some level. In client side use, Internet Explorer will stop script execution and may display an error message, though in more recent versions of Internet Explorer errors are not displayed to the user by default so they will simply 'see' that 'nothing has happened'.
  • Use exception handling to catch the error and deal with it cleanly and appropriately.
  • Test for the validity of the license in a window/document load handler and inform the user before any attempt is made to access licensed methods/properties.

The last approach is the one descibed here.

The Security Manager object provides the property validLicense that returns true if the license is valid. The result property indicates the type of reason for the failure:

...
<script>
function IsLicensed()
{
    var sm = document.getElementById("secmgr");
    return sm.result == 0 && sm.validLicense;
}
</script>