If you want to customize your scripting depending on the
particular client application in which the form or Guide is being
viewed, you can use the name property of the host model
to conditionalize your scripts. For example, the following JavaScript
executes only if the form is rendered as a Guide:
if (xfa.host.name == "Flash")
{
xfa.host.messageBox("This is executing in Flash Player!");
}
Similarly, the following JavaScript executes only if the form
is rendered in HTML format (and the form is viewed in Internet Explorer):
if (xfa.host.name == "IE")
{
xfa.host.messageBox("This is executing in Internet Explorer!");
}
Form output format
|
Client application
|
xfa.host.name
|
PDF
|
Acrobat Standard, Acrobat Professional,
Acrobat Pro Extended, and Adobe Reader
|
Acrobat
|
Guide (SWF)
|
Adobe Flash Player
|
Flash
|
HTML
|
Internet Explorer
|
Microsoft Internet Explorer
|
HTML
|
Mozilla Firefox
|
Netscape
|
HTML
|
Apple Safari
|
Netscape
|
If you want to distinguish between Firefox and Safari, you can
use the standard HTML object model to access the window.navigator.userAgent property.
The userAgent property returns a string that should contain the
name of the application. For example, for Firefox 2.0.0.13 the userAgent
property contains the following value:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13
The following JavaScript uses the String.search() method
to determine if the value of userAgent contains either Firefox or Safari,
and displays a customized message box for each case.
var sVar = window.navigator.userAgent;
if (xfa.host.name == "Netscape")
{
if (sVar.search(/FireFox/) != -1)
{
xfa.host.messageBox("This is executing in Mozilla Firefox!");
}
if (sVar.search(/Safari/) != -1)
{
xfa.host.messageBox("This is executing in Apple Safari!");
}
}
Note: Individual applications can configure the userAgent
property to display any string value. You should verify the value
of userAgent for specific versions of the HTML client application
on which your users will view the rendered form.