Scripting API

This section introduces functions for operating TLabWebView.

Initialize

Init

public void Init()
public void Init(
    int webWidth, int webHeight,
    int texWidth, int texHeight)
public void Init(
    int webWidth, int webHeight,
    int texWidth, int texHeight,
    string url, DownloadOption dlOption, string subDir)

Parameters

NameTypeDescription

webWidth

int

WebView Width

webHeight

int

WebView Height

texWidth

int

Texture2D Width

texHeight

int

Texture2D Height

url

string

URL that loads first

dlOption

DownloadOption

The directory of the device to which the content is being downloaded.

subDir

string

Subdirectory of the directory from which the content is downloaded.

IsInitialized

If it returns true, this WebView component is already initialized.

public bool IsInitialized()
TypeDescription

bool

whether or not this WebView component is initialized.

Update Frame

GetTexturePtr

Return the Texture Pointer of the WebView frame.

public IntPtr GetTexturePtr()
TypeDescription

IntPtr

texture pointer of the webview frame

UpdateFrame

Request Webview to update frame.

public void UpdateFrame()

Capture HTML Element

CaptureHTMLSource

Gaptures HTML currently displayed async.

public void CaptureHTMLSource()

CaptureElementById

Gapture specific HTML elements currently displayed async.

public void CaptureElementById(string id)

Parameters

NameTypeDescription

id

string

target html element tag

CurrentHTMLCaptured

Gets the HTML value currently captured.

public string CurrentHTMLCaptured()
TypeDescription

string

HTML value currently captured.

Load URL

LoadUrl

Loads the given URL.

public void LoadUrl(string url)

Parameters

NameTypeDescription

url

string

the URL of the resource to load.

LoadHTML

Loads the given HTML.

public void LoadHTML(string html, string baseURL)

return

NameTypeDescription

html

string

the html of the resource to load.

baseURL

string

baseURL

GoForward

Goes forward in the history of this WebView.

public void GoForward()

GoBack

Goes back in the history of this WebView.

public void GoBack()

Zoom In/Out

ZoomIn

Performs zoom in in this WebView.

public void ZoomIn()

ZoomOut

Performs zoom out in this WebView.

public void ZoomOut()

Scroll

GetScrollX

Get content's scroll position x

public int GetScrollX()

return

TypeDescription

int

Page content's current scroll position x

GetScrollY

Get content's scroll position y

public int GetScrollY()

return

TypeDescription

int

Page content's current scroll position y

ScrollTo

Set content's scroll position

public void ScrollTo(int x, int y)

Parameters

NameTypeDescription

x

int

Scroll position x of the destination

y

int

Scroll position y of the destination

ScrollBy

Move the scrolled position of webview

public void ScrollBy(int x, int y)

Parameters

NameTypeDescription

x

int

The amount of pixels to scroll by horizontally

y

int

The amount of pixels to scroll by vertically

PageUp

Scrolls the contents of this WebView up by half the view size.

public void PageUp(bool top)

Parameters

NameTypeDescription

top

bool

true to jump to the top of the page

PageDown

Scrolls the contents of this WebView down by half the page size.

public void PageDown(bool bottom)

Parameters

NameTypeDescription

bottom

bool

true to jump to bottom of page

User Agent

CaptureUserAgent

Capture current userAgent async.

public void CaptureUserAgent()

GetUserAgent

Gets the currently captured userAgent string.

public string GetUserAgent()

return

TypeDescription

string

userAnget String that is currently being captured.

SetUserAgent

Update userAgent with the given userAgent string.

public void SetUserAgent(string ua, bool reload)

Parameters

NameTypeDescription

ua

string

userAgent string

reload

bool

If true, reload web page when userAgent is updated.

Javascript

EvaluateJS

Run Javascript on the current web page.

public void EvaluateJS(string js)

Parameters

NameTypeDescription

js

string

javascript

send a message from javascript to unity.

// See sample https://github.com/TLabAltoh/TLabWebView/blob/master/Scripts/Sample/WebViewSample.cs
// The destination must be a function that takes a character type as an argument.
function() {
    window.TLabWebViewActivity.unitySendMessage(String go, String method, String message)
}

SetOnPageFinish

Register Javascript to run when the page is finished loading.

public void SetOnPageFinish(string onPageFinish)

Parameters

NameTypeDescription

onPageFinish

string

javascript

SetOnDownloadStart

Register Javascript to run when download event starts.

public void SetOnDownloadFinish(string onDownloadFinish)

Parameters

NameTypeDescription

onDownloadFinish

string

javascript

SetOnDownloadFinish

Register Javascript to run when download event finishes.

public void SetOnDownloadStart(string onDownloadStart)

Parameters

NameTypeDescription

onDownloadStart

string

javascript

Download Event

SetDlEventVariableName

Defines the download event parameter's name. it can be accessed from javascript when a download event occurs.

public void SetDlEventVariableName(
    string dl_url_name, string dl_uri_name, string dl_id_name)

Parameters

NameTypeDescription

dl_url_name

string

URL of the file to be downloaded

dl_uri_name

string

The destination for the downloaded file.

dl_id_name

string

The ID of the download event.

SetDlOption

Set the directory in which the file will be downloaded.

public void SetDlOption(DownloadOption option)

Parameters

NameTypeDescription

option

DownloadOption

Download location for the files.

DownloadOption

NameDescription

applicationFolder

Application's external files directory.

downloadFolder

Standard directory in which to place files that have been downloaded by the user.

SetSubDir

Specifies the subdirectory from which the files are to be downloaded.

public void SetSubDir(string subdir)

Parameters

NameTypeDescription

subdir

string

The subdirectory from which the files are downloaded. This directory is created under the directory specified in DownloadOption.

RequestCaptureDownloadProgress

Asynchronous capture of download event progress.

public void RequestCaptureDownloadProgress()

GetDownloadProgress

Get the progress of the download event currently being recorded.

public float GetDownloadProgress()

Interaction

TouchEvent

Dispatch of a touch event

public void TouchEvent(int x, int y, int eventNum)

Parameters

NameTypeDescription

x

int

Touch position x

y

int

Touch position y

eventNum

int

Touch event type (TOUCH_DOWN: 0, TOUCH_UP: 1, TOUCH_MOVE: 2)

KeyEvent

Dispatch of a basic keycode event

public void KeyEvent(char key)
NameTypeDescription

key

char

'a', 'b', 'A' ....

BackSapce

Dispatch of a backspace key event

public void BackSpace()

Clear Cache

ClearCache

Clear WebView Cache.

public void ClearCache(bool includeDiskFiles)
NameTypeDescription

includeDiskFiles

bool

If false, only the RAM cache will be cleared.

ClearCookie

Clear WebView Cookie.

public void ClearCookie()

ClearHistory

Clear WebView History

public void ClearHistory()

Resize

ResizeTex

Update WebView Texture Resolusion

public void ResizeTex(int texWidth, int texHeight)e code

Parameters

NameTypeDescription

texWidth

int

Texture new width

texHeight

int

Texture new height

ResizeWeb

Update WebView Resolution

public void ResizeWeb(int webWidth, int webHeight)

Parameters

NameTypeDescription

webWidth

int

WebView new width

webHeight

int

WebView new height

Resize

Update Resolusion for both WebView and Texture

public void Resize(int texWidth, int texHeight, int webWidth, int webHeight)

Parameters

NameTypeDescription

texWidth

int

Texture new width

texHeight

int

Texture new height

webWidth

int

WebView new width

webHeight

int

WebView new height

Last updated