Web Extension Toolkit is a set of External Objects to solve typical problems in Web Applications. It can be used installing the module available in Global Matrix through Knoledge Manager -> Manage Module References option
For example:
- Geolocation: Get user location position
- Close Popups programmatically
- Open new window/browser tab
- Management of the address bar of the browser (change, back, forward, etc)
- Execute JS code
- Send error messages and warning to browser console
- Subscribe to events of:
- Popup closure
- On Ready of web apps
- onUnLoad (when closing a web page)
- Display native Web dialogs for:
- Display UI Browser Alerts.
- Use of WebSocket API (management of the WebSocket low level API)
- Timer:
- Fire User Events afer elapsed time
Event 'OpenNewWindow'
if (&UseAdvancedOptions)
Extensions.Web.Window.OpenNewWindow(&Url, "",&WindowOptions)
else if (&OpenMultipleWindows)
Extensions.Web.Window.OpenNewWindow(&Url, 'myNewWindow-1')
Extensions.Web.Window.OpenNewWindow(&Url2, 'myNewWindow-2')
else
Extensions.Web.Window.OpenNewWindow(&Url)
endif
Endevent
Event 'Close Window'
Extensions.Web.Window.Close('')
EndEvent
Event Extensions.Web.Window.OnClose(&windowName)
msg(&windowName + "has beed closed!")
EndEvent
In New Window options:
Note: To open in new Tab, use the method with only URL parameter.
Extensions.Web.Window.OpenNewWindow(&Url)
Event Enter
Popup1.Popup()
Endevent
Event 'Close'
Extensions.Web.Popup.Close()
Endevent
Event Extensions.Web.Popup.OnPopupClosed(&PopupName)
msg("popup has been closed: " + &PopupName)
EndEvent
Event 'RunJS'
Extensions.Web.WebInterop.RunJS(!"console.log('hello world');alert('hello world');")
Endevent
Event 'LogError'
Extensions.Web.WebInterop.LogError(&logMessage)
Endevent
Event Extensions.Web.WebInterop.OnReady()
msg("Onready!")
EndEvent
Event Extensions.Web.WebInterop.OnUnload()
Extensions.Web.WebInterop.LogError(!"Exiting Page!")
EndEvent
Note for OnUnload Event:
- The HTML specification states that calls to window.alert(), window.confirm(), and window.prompt() methods may be ignored during this event. See the HTML specification for more details.
https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event
Event 'ShowAlert'
Extensions.Web.Dialog.Alert(&logMessage) //&LogMessage: Message that will be display within Alert Dialog
Endevent
Event 'ShowConfirm'
Extensions.Web.Dialog.Confirm(&logMessage) //&LogMessage: Message that will be display within Confirm Dialog
Endevent
Event Extensions.Web.Dialog.OnConfirmClosed(&UserResponse) //&UserResponse: MUST be a Boolean Variable.
Extensions.Web.Dialog.Alert("User Confirm Response: " + &UserResponse.ToString())
EndEvent
Event 'GetMyLocation'
Extensions.Web.Geolocation.requestLocation()
Endevent
Event Extensions.Web.Geolocation.OnError(&ErrCode, &errMessage)
msg("Geolocation Error: " + &errMessage)
EndEvent
Event Extensions.Web.Geolocation.OnLocationChanged(&GeolocationInfo)
msg(&geolocationinfo.ToJson())
EndEvent
Event 'GetLocationWithOptions'
Extensions.Web.Geolocation.requestLocation(&LocationRequestOptions)
Endevent
Event 'Show Notification'
UINotification.show(&UINotificationMessage.Id, &UINotificationMessage)
Endevent
Event 'Hide Notification'
UINotification.hide(&DeleteNotificationId)
Endevent
Event 'ShowSimple'
UINotification.show(&NotificationId, &NotificationTitle, &NotificationBody, '')
Endevent
Event UINotification.onRequestPermission(&permission) //'granted', 'denied'
msg("UINotification.requestPermission: " + &permission)
EndEvent
Event 'PushState'
Extensions.Web.History.PushState(&ResourceName)
Endevent
Event 'Replacestate'
Extensions.Web.History.ReplaceState(&ResourceName)
Endevent
Event 'GoBack'
Extensions.Web.History.GoBack()
Endevent
Event 'GoForward'
Extensions.Web.History.GoForward()
Endevent
Installation instructions:
GeneXus v17 U5 or higher:
- In Genexus, Menu -> Knowledge Manager -> Open "Manage Module References"
- Select Global Matrix, Install "WebExtensionToolkit". (Requires Maven. Installation will fail if not installed)
Ready to use!
GeneXus v17 U4 or lower:
- Download .OPC file from Marketplace
- In Genexus, Menu -> Knowledge Manager -> Open "Manage Module References".
- In the dialog on the left, right click -> "Upload from file". Select the .opc file
- Install
- Copy file "gx-web-extensions.js" (download it here) to the WEB folder.
- Copy file "gx-grid-freeze.js" (download it here) to the WEB folder. (If using Grid.FreezeColumns)
Additionally, For GeneXus V15 U8 or lower (ONLY)
Add the following code:
- .NET: Form.HeaderRawHTML += !'<script type="text/javascript" src="gx-web-extensions.js" data-gx-external-script=""></script>'
- .JAVA: Form.HeaderRawHTML += !'<script type="text/javascript" src="../static/gx-web-extensions.js" data-gx-external-script=""></script>'
javax.servlet.ServletException: java.lang.NoClassDefFoundError: com/webinterop/extensions/web/SdtWindowOptions
- Check if "Web\modules\Extensions.jar" has been copied to "WEB-INF\Lib" directory
js error: cannot read 'web' of undefined or 404 not found
error: Error downloading module 'WebExtensionToolkit' from 'GeneXusMatrix' (internal error: 'Object reference not set to an instance of an object.').
In gxlogging.log you can see the following error:
PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested
Reason: GeneXus requires Maven 3.6.1 or higher for installing modules from a Nexus Modules Server.
Solution: You must install/update Maven. Maven needs to be added to the System Path. Also, it is necessary to update the JDK or manually update the certificate in the Java version of the development machine, so that the new certificate used by the Matrix server is recognized. This will allow to establish a secure connection and resolve the error. More information is available at SAC #52914.