The goal of this script is to:
- Prompt a user to enter their name the first time they run the application.
- Store the name in a persistent global variable.
- Display the name on an HTML page.
Steps #
We will name our global variable TheUserName.
Step 1: Write the Script #
Go to the Script Manager, double-click on UserMain, and paste this script into the OnPubLoaded function event:
function OnPubLoaded: Boolean;
var
S: String;
begin
// Check if the user was already prompted.
// If the `TheUserName` global variable already has a value, do not prompt the user again.
if GetGlobalVar("TheUserName", "") <> "" then exit;
// Prompt the user.
S := InputBox("Welcome!"#13#10"Please enter your name:", "What is your name?", "");
// If the user does not provide a name, set it to "Mysterious User".
if S = "" then
S := "Mysterious User"
else
begin
// Store the result only if the user has provided a name.
// This way, they will be prompted again next time if they leave it blank.
SetGlobalVar("TheUserName", S, True);
// `True` means the global variable is persistent.
end;
// This event occurs when the application is starting, before the homepage is displayed.
// Set `Result` to `True` to exit immediately without any warning.
Result := False;
end;Step 2: Display the Name in an HTML Page #
Use this JavaScript code:
document.write(window.external.GetGlobalVariable('TheUserName', ''));Notes #
You can, of course, customize this example. Instead of using a dialog box, you could display an HTML page at startup.