Titanium.UI.WebView

Object of Titanium.UI.
Platform Since
Android 0.8
iPhone 0.8
iPad 0.8
Mobile Web 1.8

Summary

The web view allows you to open an HTML5 based view which can load either local or remote content.

Description

The web view content can be any valid web content such as HTML, PDF, SVG or other WebKit supported content types.

JavaScript in the web view executes in its own context. When running local web content (that is, content that is included in the application's resources), scripts have access to the Titanium namespace. In particular, when running local web content:

Scripts downloaded from remote web servers cannot access the Titanium namespace, however, you can use the web view evalJS method to execute a JavaScript expression inside the web view, and retrieve the value of an expression.

Use the Titanium.UI.createWebView method to create a web view.

Web views are more expensive to create than other native views because of the requirement to load the HTML browser into memory.

The native web view handles scrolling and other related touch events internally. If you add event listeners for any of the standard touch events (touchstart, click, and so on), these events do not reach the native web view, and the user will not be able to scroll, zoom, click on links, and so on.

In other words, you can have either Titanium-style events against the web view instance, or internal JavaScript events in the DOM, but not both.

Note that on the iOS platform, any touch event listeners on the web view or its parent views will prevent users from interacting with the native web view. To prevent this default behavior, set willHandleTouches to false.

Android Platform Implementation Notes

The Android web view supports native plugins such as Flash Player. To use plugin content, you must set the pluginState property to either WEBVIEW_PLUGINS_ON or WEBVIEW_PLUGINS_ON_DEMAND.

You must also call pause when the current activity is paused, to prevent plugin content from continuing to run in the background. Call resume when the current activity is resumed. You can do this by adding listeners for the Activity.pause and Activity.resume events.

Code Examples

Basic Web View to External URL

Create a web view to a remote URL and open the window as modal.

var webview = Titanium.UI.createWebView({url:'http://www.appcelerator.com'});
    var window = Titanium.UI.createWindow();
    window.add(webview);
    window.open({modal:true});

Methods

Name Summary
add

Adds a child to this view's hierarchy.

addEventListener

Adds the specified callback as an event listener for the named event.

animate

Animates this view.

canGoBack

Returns true if the web view can go back in its history list.

canGoForward

Returns true if the web view can go forward in its history list.

convertPointToView

Translates a point from this view's coordinate system to another view's coordinate system. (Android, iPhone, iPad only.)

evalJS

Evaluates a JavaScript expression inside the context of the web view and optionally, returns a result.

fireEvent

Fires a synthesized event to any registered listeners.

getAnchorPoint

Gets the value of the anchorPoint property. (iPhone, iPad only.)

getAnimatedCenterPoint

Gets the value of the animatedCenterPoint property. (Android, iPhone, iPad only.)

getBackgroundColor

Gets the value of the backgroundColor property.

getBackgroundDisabledColor

Gets the value of the backgroundDisabledColor property. (Android only.)

getBackgroundDisabledImage

Gets the value of the backgroundDisabledImage property. (Android only.)

getBackgroundFocusedColor

Gets the value of the backgroundFocusedColor property. (Android only.)

getBackgroundFocusedImage

Gets the value of the backgroundFocusedImage property. (Android only.)

getBackgroundGradient

Gets the value of the backgroundGradient property. (iPhone, iPad, Mobile Web only.)

getBackgroundImage

Gets the value of the backgroundImage property.

getBackgroundLeftCap

Gets the value of the backgroundLeftCap property. (iPhone, iPad only.)

getBackgroundRepeat

Gets the value of the backgroundRepeat property. (iPhone, iPad only.)

getBackgroundSelectedColor

Gets the value of the backgroundSelectedColor property. (Android, Mobile Web only.)

getBackgroundSelectedImage

Gets the value of the backgroundSelectedImage property. (Android, Mobile Web only.)

getBackgroundTopCap

Gets the value of the backgroundTopCap property. (iPhone, iPad only.)

getBorderColor

Gets the value of the borderColor property.

getBorderRadius

Gets the value of the borderRadius property.

getBorderWidth

Gets the value of the borderWidth property.

getBottom

Gets the value of the bottom property.

getCenter

Gets the value of the center property.

getChildren

Gets the value of the children property.

getData

Gets the value of the data property.

getEnableZoomControls

Gets the value of the enableZoomControls property. (Android only.)

getFocusable

Gets the value of the focusable property. (Android only.)

getHeight

Gets the value of the height property.

getHtml

Gets the value of the html property.

getKeepScreenOn

Gets the value of the keepScreenOn property. (Android only.)

getLayout

Gets the value of the layout property.

getLeft

Gets the value of the left property.

getLoading

Gets the value of the loading property.

getOpacity

Gets the value of the opacity property.

getPluginState

Gets the value of the pluginState property. (Android only.)

getRight

Gets the value of the right property.

getScalesPageToFit

Gets the value of the scalesPageToFit property. (Android, iPhone, iPad only.)

getShowScrollbars

Gets the value of the showScrollbars property. (Mobile Web only.)

getSize

Gets the value of the size property.

getSoftKeyboardOnFocus

Gets the value of the softKeyboardOnFocus property. (Android only.)

getTop

Gets the value of the top property.

getTouchEnabled

Gets the value of the touchEnabled property.

getTransform

Gets the value of the transform property.

getUrl

Gets the value of the url property.

getUserAgent

Gets the value of the userAgent property. (Android only.)

getVisible

Gets the value of the visible property.

getWidth

Gets the value of the width property.

getWillHandleTouches

Gets the value of the willHandleTouches property. (iPhone, iPad only.)

getZIndex

Gets the value of the zIndex property.

goBack

Goes back one entry in the web view's history list, to the previous page.

goForward

Goes forward one entry in this web view's history list, if possible.

hide

Hides this view.

pause

Pauses native webview plugins. (Android only.)

reload

Reloads the current webpage.

remove

Removes a child view from this view's hierarchy.

removeEventListener

Removes the specified callback as an event listener for the named event.

repaint

Forces the web view to repaint its contents. (iPhone, iPad only.)

resume

Resume native webview plugins. (Android only.)

setAnchorPoint

Sets the value of the anchorPoint property. (iPhone, iPad only.)

setBackgroundColor

Sets the value of the backgroundColor property.

setBackgroundDisabledColor

Sets the value of the backgroundDisabledColor property. (Android only.)

setBackgroundDisabledImage

Sets the value of the backgroundDisabledImage property. (Android only.)

setBackgroundFocusedColor

Sets the value of the backgroundFocusedColor property. (Android only.)

setBackgroundFocusedImage

Sets the value of the backgroundFocusedImage property. (Android only.)

setBackgroundGradient

Sets the value of the backgroundGradient property. (iPhone, iPad, Mobile Web only.)

setBackgroundImage

Sets the value of the backgroundImage property.

setBackgroundLeftCap

Sets the value of the backgroundLeftCap property. (iPhone, iPad only.)

setBackgroundRepeat

Sets the value of the backgroundRepeat property. (iPhone, iPad only.)

setBackgroundSelectedColor

Sets the value of the backgroundSelectedColor property. (Android, Mobile Web only.)

setBackgroundSelectedImage

Sets the value of the backgroundSelectedImage property. (Android, Mobile Web only.)

setBackgroundTopCap

Sets the value of the backgroundTopCap property. (iPhone, iPad only.)

setBasicAuthentication

Sets the basic authentication for this web view to use on subsequent URl requests. (Android, iPhone, iPad only.)

setBorderColor

Sets the value of the borderColor property.

setBorderRadius

Sets the value of the borderRadius property.

setBorderWidth

Sets the value of the borderWidth property.

setBottom

Sets the value of the bottom property.

setCenter

Sets the value of the center property.

setData

Sets the value of the data property.

setEnableZoomControls

Sets the value of the enableZoomControls property. (Android only.)

setFocusable

Sets the value of the focusable property. (Android only.)

setHeight

Sets the value of the height property.

setHtml

Sets the value of html property. (iPhone, iPad, Mobile Web only.)

setKeepScreenOn

Sets the value of the keepScreenOn property. (Android only.)

setLayout

Sets the value of the layout property.

setLeft

Sets the value of the left property.

setLoading

Sets the value of the loading property.

setOpacity

Sets the value of the opacity property.

setPluginState

Sets the value of the pluginState property. (Android only.)

setRight

Sets the value of the right property.

setScalesPageToFit

Sets the value of the scalesPageToFit property. (Android, iPhone, iPad only.)

setShowScrollbars

Sets the value of the showScrollbars property. (Mobile Web only.)

setSoftKeyboardOnFocus

Sets the value of the softKeyboardOnFocus property. (Android only.)

setTop

Sets the value of the top property.

setTouchEnabled

Sets the value of the touchEnabled property.

setTransform

Sets the value of the transform property.

setUrl

Sets the value of the url property.

setUserAgent

Sets the value of the userAgent property. (Android only.)

setVisible

Sets the value of the visible property.

setWidth

Sets the value of the width property.

setWillHandleTouches

Sets the value of the willHandleTouches property. (iPhone, iPad only.)

setZIndex

Sets the value of the zIndex property.

show

Makes this view visible.

stopLoading

Stops loading a currently loading page.

toImage

Returns an image of the rendered view, as a Blob. (Android, iPhone, iPad only.)

Properties

Name Type Summary
anchorPoint Point

Anchor point where animation should occur, relative to the view's boundaries. (iPhone, iPad only.)

animatedCenterPoint Point

Current position of the view during an animation. (Android, iPhone, iPad only.) read-only

backgroundColor String

Background color of the view.

backgroundDisabledColor String

Disabled background color of the view. (Android only.)

backgroundDisabledImage String

Disabled background image for the view, specified as a local file path or URL. (Android only.)

backgroundFocusedColor String

Focused background color of the view. (Android only.)

backgroundFocusedImage String

Focused background image for the view, specified as a local file path or URL. (Android only.)

backgroundGradient Gradient

A background gradient for the view. (iPhone, iPad, Mobile Web only.)

backgroundImage String

Background image for the view, specified as a local file path or URL.

backgroundLeftCap Number

Size of the left end cap. (iPhone, iPad only.)

backgroundRepeat Boolean

Toggle for whether or not to tile a background across a view. (iPhone, iPad only.)

backgroundSelectedColor String

Selected background color of the view. (Android, Mobile Web only.)

backgroundSelectedImage String

Selected background image url for the view, specified as a local file path or URL. (Android, Mobile Web only.)

backgroundTopCap Number

Size of the top end cap. (iPhone, iPad only.)

borderColor String

Border color of the view.

borderRadius Number

Border radius of the view.

borderWidth Number

Border width of the view.

bottom Number or String

View's bottom position, in platform-specific units.

center Point

View's center position, in the parent view's coordinates.

children Array<Titanium.UI.View>

Array of this view's child views. read-only

data Titanium.Blob or Titanium.Filesystem.File

Web content to load.

enableZoomControls Boolean

If true, zoom controls are enabled. (Android only.)

focusable Boolean

Whether view should be focusable while navigating with the trackball. (Android only.)

height Number or String

View height, in platform-specific units.

html String

HTML content of this web view.

keepScreenOn Boolean

Whether to keep the device screen on. (Android only.)

layout String

Specifies how the view positions its children. One of: 'absolute', 'vertical', or 'horizontal'.

left Number or String

View's left position, in platform-specific units.

loading Boolean

Indicates if the webview is loading content.

opacity Number

Opacity of this view, from 0.0 (transparent) to 1.0 (opaque).

pluginState Number

Determines how to treat content that requires plugins in this web view. (Android only.)

right Number or String

View's right position, in platform-specific units.

scalesPageToFit Boolean

If true, scale contents to fit the web view. (Android, iPhone, iPad only.)

showScrollbars Boolean

If true, scrollbars are displayed if content is larger than the web view. (Mobile Web only.)

size Object

Rendered size of the view as a dictionary of width and height properties. read-only

softKeyboardOnFocus Number

Determines keyboard behavior when this view is focused. (Android only.)

top Number or String

The view's top position.

touchEnabled Boolean

Whether view should receive touch events.

transform Titanium.UI.2DMatrix or Titanium.UI.iOS.3DMatrix

Transformation matrix to apply to the view.

url String

URL to the web document.

userAgent String

The User-Agent header used by the web view when requesting content. (Android only.)

visible Boolean

Boolean value indicating whether the view is visible.

width Number or String

View's width, in platform-specific units.

willHandleTouches Boolean

Explicitly specifies if this web view handles touches. (iPhone, iPad only.)

zIndex Number

Z index position relative to other sibling views.

Events

Name Summary
beforeload

Fired before the web view starts loading its content.

click

Fired when the device detects a click against the view.

dblclick

Fired when the device detects a double click against the view.

doubletap

Fired when the device detects a double tap against the view. (Android, iPhone, iPad only.)

error

Fired when the web view cannot load the content.

load

Fired when the web view content is loaded.

longclick

Fired when the device detects a long click. (Android only.)

longpress

Fired when the device detects a long press. (Android, iPhone, iPad only.)

pinch

Fired when the device detects a pinch gesture. (iPhone, iPad only.)

singletap

Fired when the device detects a single tap against the view.

swipe

Fired when the device detects a swipe gesture (left or right) against the view. (iPhone, iPad, Mobile Web only.)

touchcancel

Fired when a touch event is interrupted by the device.

touchend

Fired when a touch event is completed.

touchmove

Fired as soon as the device detects movement of a touch.

touchstart

Fired as soon as the device detects a touch gesture.

twofingertap

Fired when the device detects a two-finger tap against the view.