Class

# WebTimer

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Creates a client-side (browser) timer that executes code based on the time set. This control has no visual user interface but it appears on the Shelf in the Web Page Layout Editor.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                              | Type                                             | Read-Only | Shared |
|-----------------------------------|--------------------------------------------------|-----------|--------|
| `ControlID<webtimer.controlid>`   | `String</api/data_types/string>`                 | ✓         |        |
| `Enabled<webtimer.enabled>`       | `Boolean</api/data_types/boolean>`               |           |        |
| `Location<webtimer.location>`     | `Locations<webtimer.locations>`                  |           |        |
| `Name<webtimer.name>`             | `String</api/data_types/string>`                 | ✓         |        |
| `PanelIndex<webtimer.panelindex>` | `Integer</api/data_types/integer>`               |           |        |
| `Page<webtimer.page>`             | `WebPage</api/user_interface/web/webpage>`       | ✓         |        |
| `Parent<webtimer.parent>`         | `WebControl</api/user_interface/web/webcontrol>` | ✓         |        |
| `Period<webtimer.period>`         | `Integer</api/data_types/integer>`               |           |        |
| `RunMode<webtimer.runmode>`       | `RunModes<webtimer.runmodes>`                    |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                            | Parameters                                                                                                                                                                     | Returns | Shared |
|-------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|--------|
| `CallLater<webtimer.calllater>`                 | afterMilliseconds As `Integer</api/data_types/integer>`, method As `Timer.TimerCallLater<timer.timercalllater>`                                                                |         | ✓      |
|                                                 | afterMilliseconds As `Integer</api/data_types/integer>`, method As `Timer.TimerCallLaterWithValue<timer.timercalllaterwithvalue>`, value As `Variant</api/data_types/variant>` |         | ✓      |
| `Close<webtimer.close>`                         |                                                                                                                                                                                |         |        |
| `ExecuteJavaScript<webtimer.executejavascript>` | Script As `String</api/data_types/string>`                                                                                                                                     |         |        |
| `GotoURL<webtimer.gotourl>`                     | Url As `String</api/data_types/string>`, inNewWindow As `Boolean</api/data_types/boolean>` = `False</api/language/false>`                                                      |         |        |
| `Reset<webtimer.reset>`                         |                                                                                                                                                                                |         |        |
| `UpdateBrowser<webtimer.updatebrowser>`         |                                                                                                                                                                                |         |        |

## Events

<div class="rst-class">

table-centered_column_4

</div>

| Name                        | Parameters | Returns |
|-----------------------------|------------|---------|
| `Closed<webtimer.closed>`   |            |         |
| `Opening<webtimer.opening>` |            |         |
| `Run<webtimer.run>`         |            |         |

## Enumerations

<div id="webtimer.locations">

<div class="rst-class">

forsearch

</div>

</div>

WebTimer.Locations

### Locations

> Locations where a timer can run.
>
> | Enum    | Description                        |
> |---------|------------------------------------|
> | Browser | The timer runs in the web browser. |
> | Server  | The timer runs on the server.      |

<div id="webtimer.runmodes">

<div class="rst-class">

forsearch

</div>

</div>

WebTimer.RunModes

### RunModes

> Designates the minimum interval at which a timer can run.
>
> | Enum     | Description                                                                                                                |
> |----------|----------------------------------------------------------------------------------------------------------------------------|
> | Multiple | The timer will repeatedly execute the Action event every `Period<webtimer.period>` milliseconds. This is the default mode. |
> | Off      | The timer will not execute the Action event at all.                                                                        |
> | Single   | Time timer will execute the Action event just once.                                                                        |

## Property descriptions

<div id="webtimer.controlid">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebTimer.ControlID

**ControlID** As `String</api/data_types/string>`

> Identifies the control on a per session basis.
>
> This property is read-only.

<div id="webtimer.enabled">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebTimer.Enabled

**Enabled** As `Boolean</api/data_types/boolean>`

> When `True</api/language/true>` the **WebControl** is drawn enabled and responds to user action. When `False</api/language/false>`, the control appears as disabled and does not respond to user actions.
>
> In the case of <span class="title-ref">WebTimer</span>, when set to `False</api/language/false>` this disables and stops the <span class="title-ref">WebTimer</span>. When set to `True</api/language/true>`, it starts the <span class="title-ref">WebTimer</span>.
>
> Disable a button when a check box value changes:
>
> ``` xojo
> If AllowSaveCheckBox.Value Then
>   SaveButton.Enabled = True
> Else
>   AllowSaveButton.Enabled = False
> End If
> ```

<div id="webtimer.location">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebTimer.Location

**Location** As `Locations<webtimer.locations>`

> Indicates where the timer will run. See `Locations<webtimer.locations>` for details.
>
> You should only set this property in the Inspector for the <span class="title-ref">WebTimer</span>. Changing it in code has no effect.

<div id="webtimer.name">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebTimer.Name

**Name** As `String</api/data_types/string>`

> The name of the control.
>
> This property is read-only.

<div id="webtimer.panelindex">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebTimer.PanelIndex

**PanelIndex** As `Integer</api/data_types/integer>`

> If the control has been placed on a <span class="title-ref">WebTabPanel</span> or `WebPagePanel</api/user_interface/web/webpagepanel>` control, this is the panel (page/tab) that the control is on. If the control is not on a panel, it returns -1.
>
> The first panel is numbered zero. If the control has been placed on a panel of a <span class="title-ref">WebTabPanel</span> or `WebPagePanel</api/user_interface/web/webpagepanel>` control, it returns the panel number. If the control is not on a `WebPagePanel</api/user_interface/web/webpagepanel>` or <span class="title-ref">WebTabPanel</span>, it returns -1. If you change the PanelIndex to a nonexistent panel, the control will disappear until you give it a PanelIndex value that corresponds to a panel that exists.
>
> If you are looking to change the currently selected panel (page/tab), use `SelectedPanelIndex<webpagecontrol.selectedpanelindex>`.
>
> This code displays the panel index of the control that is on the page.
>
> ``` xojo
> MessageBox(Me.SelectedPanelIndex.ToString)
> ```

<div id="webtimer.page">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebTimer.Page

**Page** As `WebPage</api/user_interface/web/webpage>`

> Identifies the web page that contains the control.
>
> This property is read-only.

<div id="webtimer.parent">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebTimer.Parent

**Parent** As `WebControl</api/user_interface/web/webcontrol>`

> Used to get the control's parent control or page. If the parent control is a `WebContainer</api/user_interface/web/webcontainer>`, then it returns the `WebContainer</api/user_interface/web/webcontainer>`. If it is on a `WebPage</api/user_interface/web/webpage>`, it returns the `WebPage</api/user_interface/web/webpage>`.
>
> This property is read-only.

<div id="webtimer.period">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebTimer.Period

**Period** As `Integer</api/data_types/integer>`

> The time (in milliseconds) between executions. The default is 1000 (1 second).
>
> Timers are not precise. For example a value of 1000 will cause the timer to be called about once a second, not precisely every second. Other factors such as OS, the browser and other tasks they may be doing can all affect how often a timer is called. It is possible to set Period to a value that is too low to be reached by the computer that is running the application. In this case the timer will run less often than you might expect.
>
> Periods of less than or equal to zero default to a value of 1 millisecond.
>
> Set the period to so that the timer runs every 5 seconds or so:
>
> ``` xojo
> Me.Period = 5000
> ```

<div id="webtimer.runmode">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebTimer.RunMode

**RunMode** As `RunModes<webtimer.runmodes>`

> Designates the frequency at which the timer will run.
>
> Sets a timer to run just once:
>
> ``` xojo
> Timer1.RunMode = WebTimer.RunModes.Single
> ```

## Method descriptions

<div id="webtimer.calllater">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebTimer.CallLater

**CallLater**(afterMilliseconds As `Integer</api/data_types/integer>`, method As `Timer.TimerCallLater<timer.timercalllater>`)

> Used to call a *method* (without parameters), within the current `Session</api/web/session>` context, once after the specified delay in *milliseconds*.

**CallLater**(afterMilliseconds As `Integer</api/data_types/integer>`, method As `Timer.TimerCallLaterWithValue<timer.timercalllaterwithvalue>`, value As `Variant</api/data_types/variant>`)

> Used to call a *method* (with a parameter), within the current `Session</api/web/session>` context, once after the specified delay in *milliseconds*.
>
> This method is `shared</api/language/shared>`.
>
> To pass a parameter to your CallLater method, the method signature must exactly match the <span class="title-ref">WebTimer</span> Delegate signature. Specifically this means that the method must have a single parameter that is of type `Variant</api/data_types/variant>`. No other type will work (even if it can convert to Variant).
>
> Refer to the sample below to see how this is done.
>
> Suppose you want to display some help text for a few seconds and then hide it. You can do this by creating a method to clear a Label (ClearLabel):
>
> ``` xojo
> Sub ClearLabel
>   MyLabel.Text = ""
> End Sub
> ```
>
> In the initial method, you set the Label help text and then use CallLater to set it to clear it after 2 seconds:
>
> ``` xojo
> MyLabel.Text = "Help text goes here"
> WebTimer.CallLater(2000, AddressOf ClearLabel)
> ```
>
> Suppose you want to display some help text for a few seconds and then replace it with different text. You can do this by creating a method that takes the text to display as a parameter (SetLabel). Remember the Delegate method parameter must be of type `Variant</api/data_types/variant>` as shown here:
>
> ``` xojo
> Sub SetLabel(helpText As Variant)
>   MyLabel.Text = helpText
> End Sub
> ```
>
> In the initial method, you set up the Label help text and use CallLater to change it after 2 seconds:
>
> ``` xojo
> MyLabel.Text = "First help text goes here"
> WebTimer.CallLater(2000, AddressOf SetLabel, "Second help text goes here")
> ```

<div id="webtimer.close">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebTimer.Close

**Close**

> Removes the control from the page.

<div id="webtimer.executejavascript">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebTimer.ExecuteJavaScript

**ExecuteJavaScript**(Script As `String</api/data_types/string>`)

> Executes the JavaScript passed. The JavaScript passed can call a JavaScript function in a WebPageSource control.
>
> The Xojo web framework uses EcmaScript 6 which is more strict than previous versions of JavaScript. For more details, see the [EcmaScript 6 documentation](https://www.ecma-international.org/ecma-262/6.0/).
>
> This code in the Pressed event of a Button displays an alert using JavaScript:
>
> ``` xojo
> Me.ExecuteJavaScript("alert('Hello!');")
> ```
>
> This code will select the text in a WebTextField (or WebTextArea):
>
> ``` xojo
> WebTextField1.ExecuteJavascript("document.getElementById('" + _
> WebTextField1.ControlID + "_inner').select();")
> ```

<div id="webtimer.gotourl">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebTimer.GotoURL

**GotoURL**(Url As `String</api/data_types/string>`, inNewWindow As `Boolean</api/data_types/boolean>` = `False</api/language/false>`)

> Opens the passed URL in place of the current web page or downloads a file. If *inNewWindow* is True, the browser is asked to open the URL in a new window.
>
> If the browser has popup windows disabled and *inNewWindow* is True, the method silently fails and the page is not shown.
>
> If *inNewWindow* is False, the running web app is replaced with the specified URL. If you want to display an external web site within your web app, use the `WebHTMLViewer</api/user_interface/web/webhtmlviewer>` control.
>
> Display a web site in a new popup window:
>
> ``` xojo
> Me.GotoURL("http://www.wikipedia.org", True)
> ```

<div id="webtimer.reset">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebTimer.Reset

**Reset**

> Resets the <span class="title-ref">WebTimer</span> and restarts it.
>
> This code restarts the timer:
>
> ``` xojo
> Timer1.Reset
> ```

<div id="webtimer.updatebrowser">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebTimer.UpdateBrowser

**UpdateBrowser**

> Forces the current values of the control to be sent to the browser.
>
> This method is useful when you are computing values in a loop and wish to update the browser immediately rather than wait until the current method ends.
>
> This code iterates through a `RowSet</api/databases/rowset>` of `database rows</api/databases/databaserow>`, updates a `ProgressBar</api/user_interface/web/webprogressbar>` and then forces the updated `ProgressBar</api/user_interface/web/webprogressbar>` to be sent to the browser via UpdateBrowser.
>
> ``` xojo
> ProgressBar1.MaximumValue = SalesData.RowCount
>
> For Each row As DatabaseRow in SalesData
>   AnalyzeSales(row)
>   ProgressBar1.Value = ProgressBar1.Value + 1
>   ProgressBar1.UpdateBrowser
> Next
> ```

## Event descriptions

<div id="webtimer.closed">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebTimer.Closed

**Closed**

> The control has been removed from the browser either because the page has closed or the control's Close method was called.

<div id="webtimer.opening">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebTimer.Opening

**Opening**

> The control has been created and the page is opening but has not been sent to the browser yet.
>
> The Opening event handler can be used to initialize non-visual properties and settings for controls.
>
> In most cases, you should use the `Shown<webuicontrol.shown>` event to initialize controls.

<div id="webtimer.run">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

WebTimer.Run

**Run**

> Executes each time the `Period<webtimer.period>` property elapses.
>
> In the Run event handler, you put the code that you want to run when the Timer period is reached. This example shows the current date and time (including seconds) in a Label each time the timer period is reached:
>
> ``` xojo
> Label1.Text = DateTime.Now.ToString
> ```

## Notes

The <span class="title-ref">WebTimer</span> is very similar to the desktop `Timer</api/language/timer>` control. The important difference is that the <span class="title-ref">WebTimer</span> is part of the page. As a result, it is controlled from the page, which is on the client side.

A <span class="title-ref">WebTimer</span> can be used to update controls on the page, for example. A regular `Timer</api/language/timer>` control will only execute server-side, so it cannot contact the client. If you need to update a control on a page from a regular `Timer</api/language/timer>`, consider using the `UpdateBrowser<webcontrol.updatebrowser>` method.

## Sample code

The <span class="title-ref">WebTimer</span> provides the same functionality as the Desktop `Timer</api/language/timer>` control. This example updates the text on a label (SecondsPassedLabel) on the web page using the <span class="title-ref">WebTimer</span>. This code in the <span class="title-ref">WebTimer</span> updates the label:

``` xojo
SecondsPassedLabel.Text = Str(SecondsPassedLabel.Text.ToInteger + 1)
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

You can also add a button to start and stop the timer. This code is in the `WebButton.Pressed<webbutton.pressed>` event:

``` xojo
If Me.Caption = "Start" Then
  Timer1.RunMode = WebTimer.RunModes.Multiple
  Me.Caption = "Stop" ' button caption 
Else
  SecondsPassedLabel.Text = "0"
  Timer1.RunMode = WebTimer.RunModes.Off  ' Turn off the timer
  Me.Caption = "Start"
End If
```

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | Web |
| **Operating Systems** | All |

<div class="seealso">

`WebControl</api/user_interface/web/webcontrol>` parent class; `Timer</api/language/timer>`, `WebView</api/user_interface/web/webview>`

</div>
