Class
WebSDKControl
Description
WebSDKControl is a direct subclass of WebControl,
Properties
Name |
Type |
Read-Only |
Shared |
---|---|---|---|
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
Methods
Name |
Parameters |
Returns |
Shared |
---|---|---|---|
currentSession As WebSession, key As String |
✓ |
||
script As String |
|||
Events
Name |
Parameters |
Returns |
---|---|---|
request As WebRequest, response As WebResponse |
||
js As JSONItem |
||
session As WebSession |
||
session As WebSession |
Constants
These constants are designed to be used with the WebSDKControl.
Name
Description
APIVersion
WebSDK API version. 2020r1 = 7
Property descriptions
WebSDKControl.ControlID
ControlID As String
Identifies the control on a per session basis.
This property is read-only.
WebSDKControl.Enabled
Enabled As Boolean
When True the WebControl is drawn enabled and responds to user action. When False, the control appears as disabled and does not respond to user actions.
In the case of WebTimer, when set to False this disables and stops the WebTimer. When set to True, it starts the WebTimer.
Disable a button when a check box value changes:
If AllowSaveCheckBox.Value Then SaveButton.Enabled = True Else AllowSaveButton.Enabled = False End If
WebSDKControl.Name
Name As String
The name of the control.
This property is read-only.
WebSDKControl.Page
Page As WebPage
Identifies the web page that contains the control.
This property is read-only.
WebSDKControl.PanelIndex
PanelIndex As Integer
If the control has been placed on a WebTabPanel or 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 WebTabPanel or WebPagePanel control, it returns the panel number. If the control is not on a WebPagePanel or WebTabPanel, 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.
This code displays the panel index of the control that is on the page.
MessageBox(Me.SelectedPanelIndex.ToString)
WebSDKControl.Parent
Parent As WebView
Used to get the control's parent control or page. If the parent control is a WebContainer, then it returns the WebContainer. If it is on a WebPage, it returns the WebPage.
This property is read-only.
Method descriptions
WebSDKControl.BrowserCompatibility
BrowserCompatibility(currentSession As WebSession, key As String) As Variant
Calling this method gives you access to the data that was returned by Modernizr on the user's browser.
As an example, if you wanted to know if the browser supports XHR 2:
Var value As Boolean = WebSDKControl.BrowserCompatibility(Session, "xhr2")To see a list of available keys, run a web project and open the browser's developer tools. Go to the Console and type "Modernizr" and press return. You should get a list of all of the items that we check for (which is most of them except for a few which caused problems with several of our supported browsers).
This method is shared.
WebSDKControl.Close
Close
Removes the control from the page.
WebSDKControl.ExecuteJavaScript
ExecuteJavaScript(script As 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.
This code in the Pressed event of a Button displays an alert using JavaScript:
Me.ExecuteJavaScript("alert('Hello!');")This code will select the text in a WebTextField (or WebTextArea):
WebTextField1.ExecuteJavascript("document.getElementById('" + _ WebTextField1.ControlID + "_inner').select();")
WebSDKControl.GoToURL
GoToURL(url As String, inNewWindow As Boolean = 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 control.
Display a web site in a new popup window:
Me.GoToURL("http://www.wikipedia.org", True)
WebSDKControl.UpdateBrowser
UpdateBrowser
Similar to the method on WebControl, this method also sets the internal flag which indicates to the framework that your control needs a refresh on the browser and then immediately sends the update to the browser.
WebSDKControl.UpdateControl
UpdateControl(sendImmediately As Boolean = False)
Similar to the UpdateBrowser method, this method also sets the internal flag which indicates to the framework that your control needs a refresh on the browser. When sendImmediately is False, any changes made are deferred until the event loop completes. When sendImmediately is True, the changes will be sent at that very moment.
Note
Calling this method with sendImmediately set to True will override the "deferred" option of any changes before it was called.
Event descriptions
WebSDKControl.Closed
Closed
The control has been removed from the browser either because the page has closed or the control's Close method was called.
WebSDKControl.ExecuteEvent
ExecuteEvent(name As string, parameters As JSONItem) As Boolean
This event fires when an event is sent from the browser to the app using the triggerServerEvent JavaScript method. Return True if your control has handled the event.
WebSDKControl.HandleRequest
HandleRequest(request As WebRequest, response As WebResponse) As Boolean
This event fires in the same way as App.HandleURL does except that it is for requests that are only for the current control.
To trigger this event you will need to create a specially formed URL:
Var url As String = "https://www.yourdomain.com/sdk/" + Self.ControlIDSee the documentation for WebApplication.HandleURL for usage information.
WebSDKControl.JavaScriptClassName
JavaScriptClassName As String
This event fires when the control is first created to send the JavaScript constructor for your control to the browser.
WebSDKControl.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 event to initialize controls.
WebSDKControl.Serialize
Serialize(js As JSONItem)
This event fires when the framework sends the first configuration to your control in the browser, whenever a property on WebControl is changed and whenever you call the Xojo UpdateBrowser method.
WebSDKControl.SessionHead
SessionHead(session As WebSession) As String
This event fires each time a new session starts. You should return a String containing the items you wish to add to the
<head>
tag.
WebSDKControl.SessionJavascriptURLs
SessionJavascriptURLs(session As WebSession) As String()
This event fires each time a new session starts. You should return an array of URLs which point to any javascript you need for your control to function, whether it be a subclass of XojoControl or an external library. The Xojo framework will attempt to prevent duplicate URLs from being sent to the same session.
Note
One reason we supply the session object is so you can figure out whether or not items have already been delivered to a particular session.