The `Webview` is the core container used for rendering your application code. You can control certain behaviors of the webview by using this API class. The `Webview` is the core container used for rendering your application code. You can control certain behaviors of the webview by using this API class. > Note: There is currently an issue with hyperlinks on CE devices using the IE Engine: if you are attempting to click a link while holding the shift hardware key on the device, the link will not work properly. This is a known issue and is being worked on currently. ## Enabling the API This API is part of the `coreapi` extension that is included automatically. :::ruby extensions: ["coreapi"] ## JavaScript Usage Be sure to review the [JavaScript API Usage](/guide/api_js) guide for important information about using this API in JavaScript. ## Ruby Usage Be sure to review the [Ruby API Usage](/guide/api_ruby) guide for important information about using this API in Ruby. ## Enabling the API There are two methods of enabling the Webview API: * Include all ebapi modules or * Include only the API modules you need For either of these methods, you'll need to include files from the `/Enterprise Browser/JavaScript Files/Enterprise Browser` directory on the computer that you installed the Enterprise Browser. ### Include all JS API modules To include all JS APIs, you must copy the ebapi-modules.js file to a location accessible by your app's files and include the JavaScript file in your app. For instance, to include the modules file in your index.html, with the file in the same directory as your index.html, you would add the following line to the <head> section of your index.html: :::html <script type="text/javascript" charset="utf-8" src="ebapi-modules.js"></script> > Note: that the pathing for this file is relative to the current page. This will define the EB class within the page. Any page you need to use the modules will need to have the .js file included in this fashion. ### Include only the modules you need To include single APIs, you must first include the `ebapi.js` in your HTML as well as the API file you want to use. For instance, to use the Webview API, I would add the following code to my HTML file(s), assuming the API files have been copied to the same directory as the HTML. :::html <script type="text/javascript" charset="utf-8" src="ebapi.js"></script> <script type="text/javascript" charset="utf-8" src="eb.webview.js"></script> The ebapi.js file is necessary for all single API inclusions. Same as System.webViewFramework. Use full screen mode. WM, CE, Win32, Android Enable WebView zoom. Use 'enable_screen_zoom' parameter in rhoconfig.txt to configure this value. Enable WebView zoom. Use 'EnableZoom' parameter in Config.xml to configure this value. Android Show page loading indication. On Windows Mobile/CE this property can be set only in config.xml: GUI\\HourglassEnabled. At Android use 'disable_loading_indication' parameter in rhoconfig.txt to configure this value. Show page loading indication. On Windows Mobile/CE this property can be set only in config.xml: GUI\\HourglassEnabled. At Android use 'disable_loading_indication' parameter in Config.xml to configure this value. WM, CE, Android WebKit on Windows Mobile/CE Enable / disable web plug-ins. Use 'enable_web_plugins' parameter in rhoconfig.txt to configure this value. This option only has effect on Android versions before 4.0 (ICS). It mainly affects if Flash content is displayed. Enable / disable web plug-ins. Use 'enable_web_plugins' parameter in Config.xml to configure this value. This option only has effect on Android versions before 4.0 (ICS). It mainly affects if Flash content is displayed. Android Can be defined in config.xml: Navigation\\NavTimeout. Number of milliseconds(maximum is 45000) before the browser times out and navigates to the page specified in the badlink setting. If it is determined that the destination is unreachable regardless of wait time, the badlink may be loaded before NAVTIMEOUT. This is the time taken to establish communication with the server, not the time taken to fully load the page.Note that the navigation timeout will not be invoked when navigating to the start page, best practice is to store your first page locally to avoid connectivity issues at start up, you can then redirect to an online page if desired. WM WebKit Specifies the technique used to scroll about the page.Defines in config.xml: Scrolling\\ScrollTechnique. WM WebKit No scrollbars will be displayed and the page will not respond to finger swipes. When the size of the page is larger than the screen scrollbars will be presented which can be used to scroll the page. You can scroll around the page using finger swiping. Specifies the default font to use when rendering text in web pages. The specified font should be a TrueType font present on the device. On Windows the default font has been set to 'Tahoma' as this is present on all Symbol WM / CE devices, note that Tahoma has no italic or oblique variants. On the Enterprise Tablet the default is Droid Sans Fallback. The font specified must be stored in \Windows for Windows WM / CE devices, or /system/fonts for Enterprise Tablet. Defines in config.xml: HTMLStyles\\FontFamily WM WebKit Defines in config.xml: Navigation\\UserAgent. When visiting a web server the WebKit browser will report its self as the specified user agent. Use the following substitution variables: * %p - platform name ("Windows CE " + version number) * %w - WebKit version number * %e - WebKit version number. Use the UserAgent setting to spoof your device to the server, e.g. to view content designed for the desktop on your mobile screen. From RhoElements 2.1 onwards the default value was changed to work out of the box with a greater number of server configurations, prior to RhoElements 2.1 the default user agent was: "Mozilla/5.0 (%p) AppleWebKit/%w (KHTML, like Gecko) WebKit/%e Safari/%w" WM WebKit Whether to enable or disable viewport meta tag processing.Defines in config.xml: Navigation\\ViewportEnabled. WM WebKit Default viewport width to use for pages that do not have a viewport meta tag (uses 1:1 scaling if not specified).Defines in config.xml: Navigation\\ViewportWidth. WM WebKit The browser cache size, in whole MBs. Defines in config.xml: Navigation\\Cache. WM WebKit Enable / disable Browser cache. Use 'WebView.enableCache' parameter in rhoconfig.txt to configure this value. Android Configurable HTTP headers. Not yet implemented. WM WebKit Sets the zoom factor of the page. Factor 1.0 is no zoom, values less than 1.0 are zoomed out and values greater than 1.0 are zoomed in. In Windows, it is recommended to not to use the zoom value less than 1.0 because the page doesn't look in readable format. WM WebKit Sets the font size to be displayed on the page, set to 0 for the smallest font and 4 for the largest font. WM WebKit Return an active tab index. For change active tab use Use Rho.NativeTabbar.currentTab property. Force WebView to refresh the current page. TabBar tab index. If no tab bar present, index is ignored. Refresh active WebView. Force WebView to navigate to a URL. White page flickering during transition may happen if a controller action method doesn't return any rendered value, but instead performs a WebView.navigate(someUrl) call. It is important to avoid using WebView.navigate in Ruby action methods because WebView.navigate is intended to be used in callback methods asynchronously. Navigate to this url. TabBar tab index. If no tab bar present, index is ignored. Please avoid of navigate in not opened tab - this is unsupported on Android. Refresh active WebView. Force WebView to navigate to the previous page using Browser back. TabBar tab index. If no tab bar present, index is ignored. Navigate back in active WebView. Returns the relative url (location) of the current page(without server and port); the last URL loaded to WebView from Ruby controller action. If you open your page in WebView, and after it makes a few jumps by linking (for example, to outside web adresses for example), currentLocation will still return the initial url opened in WebView. Also, if you use JQMobile, current_location has the initial URL, but does not reflect the actual window.location containing the JQMobile additional address by adding #, etc. See currentUrl. TabBar tab index. If no tab bar present, index is ignored.Tab should be loaded once to return current url. Current location of active WebView. Returns the actual URL in WebView. This works the same as the JavaScript window.location.href. iOS, Android Android TabBar tab index. If no tab bar present, index is ignored. Current url of active WebView. Execute JavaScript on the current page from your controller. For most mobile platforms, WebView.execute_js has been implemented via redirection to URL with 'javascript:' schema. If WebView.execute_js used in an AJAX call handler method in the controller, it may lead to the situation where the success javascript handler will never be executed. This may happen because, at the moment of success handler should be executed, a URL of the page already has been changed. This means no handlers from the previous page are valid. The call to the JavaScript method on the current page, such as "test();". TabBar tab index. If no tab bar present, index is ignored. Execute javascript in active WebView. Use NativeTabbar.currentTab property: returns the current tab index. Use WebView.fullScreen property: Switch to / from full screen mode. When WebView loads the specified url (either by selecting link or from calling WebView.navigate), it will add this cookie to the HTTP request.Not implemented for WebKit. Android, Win32, iOS Win32, Android Set a cookie to be used by WebView for this url. One or more name-value pairs of the format "NAME=VALUE". Separate multiple name-value pairs with a semicolon, such as "NAME1=VALUE1; NAME2=VALUE2". Save current page to file system. Android Format of the saved page. Save as jpeg image. Path to the file / folder to save the page. TabBar tab index. If no tab bar present, index is ignored. If tabbar index omitted then active WebView will be saved. WM, CE,Android Use Application.nativeMenu property: set native menu items. Map of menu items: name to action. 1.0.0 WM, CE, Win32, Android, iOS, WP8 WM, CE, Win32, Android
You can call the WebView and make it execute JavaScript code from a Ruby controller. This can be particularly helpful in order to reuse JavaScript functionality that is already included in your pages.
As an example, you can invoke JQuery Mobile's changePage.
You can also call your own functions.
From the Ruby controller we can execute the JavaScript function that may be in the view.
The WebView can be set to use all the available screen real-estate by turning on "full-screen" mode.
This property can also be assigned to in JavaScript.
This is the section that will appear before the code block. :my_action)) ]]>
You can also navigate outside of your application, to an external site.
This API is also available from JavaScript.
This is the section that will appear before the code block.
The same method is available in JavaScript.
Reload the current URL into the WebView. This is useful especially after having updated data that must be now shown to the user
By default, "refresh" will update the current view. If you are using the native Tabbar and have multiple WebViews, you can specify which one to refresh.
Also available from JavaScript.