WebView

A webview that can be used to render web content in an application. More...

Import Statement: import Ubuntu.Web 0.2

Properties

Methods

Detailed Description

Here is a very simple example of how to use a WebView to render a web page:

import QtQuick 2.0
import Ubuntu.Web 0.2
WebView {
    url: "http://ubuntu.com"
}

The WebView component defaults to using a shared WebContext that is shared across all WebView instances in a given application.

See also SharedWebContext.

Property Documentation

alertDialog : component

The QML component that will be instantiated to display a JavaScript alert dialog.

See also confirmDialog, promptDialog, and beforeUnloadDialog.


beforeUnloadDialog : component

The QML component that will be instantiated to display a JavaScript confirmation when the user initiates a navigation away from the current page, if the page has defined an onBeforeUnload handler.

See also alertDialog, confirmDialog, and promptDialog.


canGoBack : bool

Whether the navigation history has a previous entry to navigate back.

See also goBack and canGoForward.


canGoForward : bool

Whether the navigation history has a next entry to navigate forward.

See also goForward and canGoBack.


confirmDialog : component

The QML component that will be instantiated to display a JavaScript confirmation dialog.

See also alertDialog, promptDialog, and beforeUnloadDialog.


context : WebContext

The web context associated to this WebView. By default a shared context is used which should fit most use cases, do not override unless you really need a finer control over the context.


contextualActions : ActionList

A list of actions that the user will be presented with when invoking a context menu (by way of a right click on desktop, or a long press on a touch-enabled device, on an image or a hyperlink). By default the list is empty, and no menu is shown. User-defined actions can access the contextual data.

Example of user-defined actions:

import Ubuntu.Components 1.1
import Ubuntu.Web 0.2
WebView {
    contextualActions: ActionList {
        Action {
            text: i18n.tr("Open link in browser")
            enabled: contextualData.href.toString()
            onTriggered: Qt.openUrlExternally(contextualData.href)
        }
    }
}

See also contextualData.


contextualData : QtObject

An object that holds the contextual data associated with the current context menu. User-defined contextual actions can use this data to process it when triggered.

It has the following properties:

  • href (url): the full URI of the hyperlink, if any
  • title (string): the title of the hyperlink, if any
  • img (url): the full URI of the image

Note that in the case of an image enclosed inside a hyperlink, both href and img will be available, allowing a user-defined contextual action to operate on both elements.

See also contextualActions.


filePicker : component

The QML component that will be instantiated to let the user select files when the user clicks an <input type="file"> element on the current page.


fullscreen : bool

Whether the current page requested fullscreen display.


icon : url

The URL of the favicon of the current page.


incognito : bool

Whether the WebView is being used in private browsing mode, where no data is persisted across sessions.


loadProgress : int

The load progress of the current page (as a integer value between 0 and 100).

See also loading.


loading : bool

Whether the current page is loading.

See also loadProgress, stop, and reload.


navigationHistory : list

The navigation history (back/forward entries) stored as a list model with a currentIndex property. Each entry exposes the URL and title of the corresponding page, as well as a timestamp of when it was visited.


promptDialog : component

The QML component that will be instantiated to display a JavaScript prompt dialog.

See also alertDialog, confirmDialog, and beforeUnloadDialog.


title : string

The title of the current page.


url : url

The URL of the current page.


Method Documentation

string getUAString()

This method can be overridden by client applications that embed a WebView to provide a static overridden user agent string. If not overridden, the default UA string and the default override mechanism will be used (see WebContext).

Note: as the user agent string is a property of the shared context, an application that embeds several WebViews that define different custom user agent strings will result in the last view instantiated setting the user agent string for all the views (unless they all use separate contexts instead of the default shared one).


void goBack()

Go back one entry in the navigation history.

See also canGoBack and goForward.


void goForward()

Go forward one entry in the navigation history.

See also canGoForward and goBack.


void loadHtml(string html, url baseUrl)

Load HTML content from memory instead of loading it from a URL. The baseUrl argument is used to resolve relative URLs in the provided content.


void reload()

Reload the current page.

See also stop.


void stop()

Stop loading the current page. Does nothing if there is no page currently loading.

See also reload and loading.