You are here: Creating a Browser Using a Constructor: kony.ui.Browser

Browser Widget

The Browser widget is a container that displays URL content in your application. A Browser widget can also display HTML/ JavaScript content.

Using Browser widget you can view HTML/JavaScript content without navigating away from the application. Browser widgets also allow you to enable third-party cookies, and enable communication to the native platforms for using platform-specific capabilities.

The three key ways to load the content of a Browser widget are as follows:

Note: In previous versions of iOS applications, Browser widget uses UIWebView class in UIKit framework by default to display its contents. Apple has deprecated UIWebView class and recommends using the WKWebView class in WebKit framework.
As UIWebView class has been deprecated and its support will be removed from Apple, you must change the Browser Type of Browser widget to WKWebView class.

Widgets are normally added to your Kony application using Kony Visualizer, but can also be added from code. For general information on using widgets in Visualizer, see Designing an Application in the Kony Visualizer User Guide.

For general information on the Browser widget see the Browser topic in the Kony Visualizer User Guide.

Note: For a more hands-on approach on the functionality of Browser widget, import and preview the Browser Feature sample app by using Kony Visualizer.

The Browser widget capabilities can be broadly categorized into the following:

 

3D Touch

MethodsDescription
registerForPeekandPop Registers a widget to enable 3D Touch peek and pop gestures.
setOnPeek Sets and overrides the existing onPeekCallback for the widget.
setOnPop Overrides the existing onPopCallback for the widget.
unregisterForPeekandPop Unregisters a widget from 3D Touch peek and pop gestures.
 
PropertiesDescription
enableFocusInTouchModeEnables or disables the Browser widget from scrolling to the top of the device screen.

Animations

MethodsDescription
animateApplies an animation to the widget.

Data Management

MethodsDescription
clearHistoryClears the page history of the specified Browser.
clearCookiesClears the cookies in the storage of the parent app in iOS platform.
clone When this method is used on a container widget, all the widgets inside the container are cloned.
getCookiesRetrieves cookies from the WKHTTPCookieStore to the parent app in iOS platform.
loadData Enables you to load the data into the Browser with the provided configuration.
setCookiesSets the cookies from WKHTTPCookieStore in the parent app in iOS platform.
setResponse Sets credentials that should be sent to the browser widget.
 
PropertiesDescription
cacheConfigUsed to configure the cachePolicy and storagePolicy of the cache responses.
clearCanvasBeforeLoadingClears the browser's canvas before data is loaded.
shareCookiesInBrowsersEnables the browsers to share cookies in iOS platform.
SSLValidationBehaviorSets the behavior of the SSL validations in iOS platform.
supportedURLSchemesProvides the strings of the SSL pinning keys which are required to launch application URLs using the Browser widget.

Layout

EventsDescription
doLayout Invoked for every widget when the widget position and dimensions are computed.
PropertiesDescription
anchorPoint Specifies the anchor point of the widget bounds rectangle using the widget's coordinate space.
bottom Determines the bottom edge of the widget and is measured from the bottom bounds of the parent container.
centerX Determines the center of a widget measured from the left bounds of the parent container.
centerY Determines the center of a widget measured from the top bounds of the parent container.
enableZoom Specifies if Zoom (ability to change the scale of the view area) must be enabled.
height Determines the height of the widget and measured along the y-axis.
leftDetermines the lower left corner edge of the widget and is measured from the left bounds of the parent container.
maxHeight Specifies the maximum height of the widget and is applicable only when the height property is not specified.
maxWidth Specifies the maximum width of the widget and is applicable only when the width property is not specified.
minHeight Specifies the minimum height of the widget and is applicable only when the height property is not specified.
minWidth Specifies the minimum width of the widget and is applicable only when the width property is not specified.
padding Defines the space between the content of the widget and the widget boundaries.
paddingInPixelIndicates if the padding is to be applied in pixels or in percentage.
right Determines the lower right corner of the widget and is measured from the right bounds of the parent container.
topDetermines the top edge of the widget and measured from the top bounds of the parent container.
width Determines the width of the widget and is measured along the x-axis.
zIndex Specifies the stack order of a widget.

Navigation Features

MethodsDescription
canGoBack Specifies whether the browser can navigate back into history.
canGoForward Specifies whether the browser can navigate forward into history.
goBack Provides you with the ability to navigate one step back in the browser history.
goForward Provides you with the ability to navigate one step forward in the browser history.
reload Provides you with the ability to reload the current web page.

User Input Handling

EventsDescription
onScrollWidgetPosition This event callback is invoked by the platform when the widget location position gets changed on scrolling.
onReachingBegining Specifies the scrolling events which gets called when scrolling reaches beginning of the widget.
onReachingEnd Specifies the scrolling events which gets called when scrolling reaches the end of the widget.
MethodsDescription
addGestureRecognizer Allows you to set a gesture recognizer for a specified gesture for a specified widget.
removeGestureRecognizer Allows you to remove the specified gesture recognizer for the specified widget.
setGestureRecognizer Allows you to set a gesture recognizer for a specified gesture for a specified widget.
PropertiesDescription
enableFocusInTouchModeEnables or disables the Browser widget from scrolling to the top of the device screen.
enableParentScrollingWhenReachToBoundaries Makes the content of the Browser scrollable.
scrollsToTop Enables you to scroll the Browser to top, on tapping a device’s status bar.

Enabling RTL

PropertiesDescription
retainContentAlignmentHelps to retain the content alignment of the widget while applying RTL.
retainFlexPositionPropertiesHelps to retain the left, right and padding properties while applying RTL.
retainFlowHorizontalAlignmentEnables you to change the horizontal flow of the widget from left to right.

Miscellaneous

MethodsDescription
evaluateJavaScript Accepts a JavaScript snippet in the form of a string.
evaluateJavaScriptAsync Accepts a JavaScript snippet and a callback function as inputs.
getBadge Enables you to read the badge value (if any) attached to the specified widget.
getHTMLFilesInWebFolderRetrieves a list of the HTML files of the specified type.
isCordovaAppsEnabledRetrieves a Boolean value that indicates whether Apache Cordova apps are enabled.
isHtmlPreviewEnabledRetrieves a Boolean value that indicates whether your app can open an HTML preview.
isWebAppDevelopmentEnabledRetrieves a Boolean value indicating whether web app development is enabled in the app.
setBadge Enables you to set the badge value to the given widget at the upper, right corner of the widget.
setSafeBrowsingResponse Sets an action for a Browser widget, when the onSafeBrowsingHit event is triggered.
PropertiesDescription
allowsInlineMediaPlayback Enables you to play a video inline in a Browser widget .
baseURL Used to configure the base URL that is displayed when a browser is rendered.
bouncesSpecifies whether the scroll view bounces past the edge of the content and back again.
browserTypeSpecifies the type of the web view used to load the web pages in iOS applications.
cursorTypeSpecifies the type of mouse pointer used.
detectTelNumber Specifies if the Browser widget must support the detection of phone numbers in the web page and display the phone numbers as clickable Phone links.
enableOverviewMode Specifies whether the browser should load pages in overview mode.
enableNativeCommunication Enables web apps to access Kony native capabilities from within the web app's JavaScript code.
enableSafeBrowsing Enables or disables the Safe Browsing feature in a Browser widget.
enableSoftwareRendering Sets the rendering of the browser contents using software, not hardware.
enableThirdPartyCookiesSpecifies if third party cookies must be enabled.
htmlString Specifies the HTML content for the Browser widget.
opacity Specifies the opacity of the widget.
playVideoInFullScreen You can use this property to enable Full Screen viewing of videos in webpages in Browser widget.
requestURLConfig Specifies the configurations for the requested URL in key-value pairs as a JavaScript object or Lua table.
screenLevelWidget Specifies whether the widget should occupy the whole container or not when your Browser widget has a large HTML content to display.
showProgressIndicatorSpecifies if the progress indicator must be displayed before loading the URL or executing an event.
settingsHelps you to configure the Browser Widget settings.
transformContains an animation transformation that can be used to animate the widget.
useWideViewportSpecifies whether the browser should enable support for the "viewport" HTML meta tag or should use the wide viewport.
zoomDensity Specifies the default zoom density of the page.
 
Events Description
handleRequestAn event callback which gets invoked by the platform before browser widget navigates to a new URL.
onFailure An event callback which gets invoked by the platform when the given URL fails to load.
onPageFinishedSent when a page is finished loading.
onPageStarted Sent when a page starts loading.
onProgressChanged Shows you the progress of the page loading in the Browser Widget.
onReceiveTriggered whenever a page is loaded that has an event callback such as digest authentication.
onSafeBrowsingHitRegisters a callback that notifies the application that a loading URL has been flagged by Safe Browsing.
onSuccess Invoked by the platform when the given request URL is successful in loading the data.

Configurations common to all widgets

MethodsDescription
convertPointFromWidget Allows you to convert the coordinate system from a widget to a point (receiver's coordinate system).
convertPointToWidget Using the convertPointToWidget method, you can modify the co-ordinate system.
removeFromParentAllows you to remove a child widget from a parent widget.
setEnabledSpecifies the widget that must be enabled or disabled.
setFocus Specifies the widget on which there must be focus.
setVisibilityUse this method to set the visibility of the widget.
Properties

Description

accessibilityConfig Enables you to control accessibility behavior and alternative text for the widget.
isVisible Controls the visibility of a widget on the form.
enableCache Enables you to improve the performance of Positional Dimension Animations.
idid is a unique identifier of Browser widget consisting of alpha numeric characters.
info A custom JSObject with the key value pairs that a developer can use to store the context with the widget.
parent Helps you access the parent of the widget.

Browser Widget Basics

In This Section information on how to program with the Browser Widget.

Creating a Browser Using a Constructor: kony.ui.Browser

You can dynamically create an instance of the Browser widget as follows.


var webtemp = new kony.ui.Browser(basicConf, layoutConf, pspConf);

Note: The configuration properties should be passed only in the respective configuration objects otherwise they are ignored

  1. Use the requestURLConfig property to specify the HTML content (static HTML content or a URL), as in the following example.

    
    var urlConf = {
        URL: "help/index.html",
        requestMethod: constants.BROWSER_REQUEST_METHOD_GET
    };
    
    var webBasic = {
        id: "browserID",
        isVisible: true,
        requestURLConfig: UrlConf
    };
    var webLayout = {
        containerHeight: 100
    };
    var webPsp = {};
    var browserID = new kony.ui.Browser(webBasic, webLayout, webPsp);
    frm1.add(browserID);
  2. (Optional) If you choose to display HTML content from a URL, specify onfailure and onsuccess Events.
  3. (Optional) You can choose to display a loading screen while the content is being loaded from a URL. For more information about the loading screen, see the Windows Library section of the Kony API Reference Guide.
  4. (Optional) On iPhone platform, you can move back and forward through the web page history using the Browser Methods.

Changing the Text Size through the Larger Text option in iOS

You can now change the text size of Browser widget through the Larger Text option from Settings -> General -> Accessibility -> Larger Text in iOS.

To support this feature, you must implement the 'dynamicTypeList' dictionary in the kony.application.setApplicationBehaviors function as follows:


kony.application.setApplicationBehaviors({
    dynamicTypeList: {
        enableChangeTextSizeFromAccessibility: true,
        fontTextStyle: constants.FONT_TEXT_STYLE_BODY
    }
});

Input Parameters

To make the Browser widget compatible with this feature, you must set the font in the css or modify the inline style as follows:

Inline Style


<h1 style=”font:-apple-system-body”>

In CSS


h1

{font: -apple-system-headline;}

The following values are supported for the font in the Browser widget:

Platform Availability

Limitations

Accessing Native Functionality

For security reasons it is important that web apps in the Browser widget do not have access to Kony native capabilities by default. Therefore, when your app starts, this access is disabled. However, you can enable it by setting the Browser widget's enableNativeCommunication property. Your app can only set this property in the Browser widget's constructor. After the constructor executes, this property is read-only.

Executing JavaScript in the Native Context

If your app sets the enableNativeCommunication property to true when it starts, then your app can call the kony.evaluateJavaScriptInNativeContext API to execute Kony JavaScript functions within the context of your web app's JavaScript modules.

JavaScript modules within your web app are the JavaScript modules in the LocalFiles folder, or one of its subfolders.

Your app can also include JavaScript modules that are executed in the Kony native context. These modules are located in the Modules folder in your project, or one of its subfolders. JavaScript modules in the Modules folder generally contain event handlers for form events, functions to help process application data. So your app can be a hybrid app that uses widgets, JavaScript, and other Kony Visualizer User Guide capabilities together with bundled web content that is hosted in a Browser widget.

If your app is a hybrid app that contains JavaScript modules that are executed in the Kony native context (i.e., modules located in Modules folder, or one of its subfolders), it can call globally available functions and execute them within the web app's context by invoking the Browser widget's evaluateJavaScript method. The call would look similar to the following example.

browserWidget.evaluateJavaScript("displayAlert(‘Hello World’)");

Security Considerations

Kony recommends that you only enable the enableNativeCommunication property for local packaged content, not for dynamically downloaded content.

There is a known security risk on the Android operating system for versions 4.1 (API 16) or earlier. Kony highly recommends that you not enable the enableNativeCommunication property on any version of Android prior to 4.2 (API 17).

Push Notifications

When using push notifications with the Browser widget, your app should never bypass Kony push notifications to use Cordova push notifications. This will cause an error. Always use the Kony push notifications rather than the Cordova push notifications.

Important Considerations

The Browser widget has the following important considerations:

i18N Keys

The Android platform has introduced a set of i18N keys to configure the Geo Location Alert as per the end-user's choice. The following are the platform-defined i18N keys with default values. You can override the default values.

Type

String

Read/Write

Read + Write

Example

kony.i18n.updateResourceBundle({
        "platform.web.geolocation.alert.description": "SpanishDescription",
        "platform.web.geolocation.alert.accept": "SpanishAccept",
        "platform.web.geolocation.alert.decline": "SpanishDecline",
        "platform.web.geolocation.alert.title ": "",
        "SpanishTitle ": "",
        "platform.web.geolocation.alert.remember": "SpanishRemember"
    },

    "es_US"
);

Accessible from IDE

Yes

Platform Availability

Android

premCopyright © 2012 Kony, Inc. All rights reserved.
premCopyright © 2012 Kony, Inc. All rights reserved.