Platforms to show: All Mac Windows Linux Cross-Platform

Back to WKWebViewControlMBS control.

WKWebViewControlMBS.addScriptMessageHandler(Name as String)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 18.0 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Adds a script message handler.
Example
// register once
browser.addScriptMessageHandler "test"
// later use in javascript:
browser.EvaluateJavaScript("window.webkit.messageHandlers.test.postMessage('Hello');")

Name: The name of the message handler.

Adding a script message handler with name name causes the JavaScript function window.webkit.messageHandlers.name.postMessage(messageBody) to be defined in all frames in all web views that use the user content controller.

WKWebViewControlMBS.addUserScript(userScript as WKUserScriptMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 19.5 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Adds an user script.

WKWebViewControlMBS.EvaluateJavaScript(JavaScript as String, byref Error as NSErrorMBS) as Variant

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Evaluates JavaScript.
Example
Var e As NSErrorMBS

// returns array of variants with doubles
Var v As Variant = WKWebViewControlMBS1.EvaluateJavaScript("o = [1,2,3];", e)
Var vd() As Variant = v

// returns array of variants with strings
Var vv As Variant = WKWebViewControlMBS1.EvaluateJavaScript("o = [""a"",""b"",""d""];", e)
Var vs() As Variant = vv

// returns dictionary
Var v3 As Variant = WKWebViewControlMBS1.EvaluateJavaScript("o = {a:1}", e)
Var dd As Dictionary = v3

Break

Synchronous version which waits for JavaScript to return the value.
Error is set in case of errors.

Result is converted from JavaScript data types to Xojo datatypes, usually variants, dictionaries or array of variants.

See also:

WKWebViewControlMBS.EvaluateJavaScript(JavaScript as String, Tag as String = "")

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 16.5 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Evaluates JavaScript.

Calls later JavaScriptEvaluated event with result and passed tag value.

Result is converted from JavaScript data types to Xojo datatypes, usually variants, dictionaries or array of variants.

See also:

WKWebViewControlMBS.goBack

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 16.4 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Navigates to the back item in the back-forward list.

Sets Navigation property.

WKWebViewControlMBS.goForward

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 16.4 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Navigates to the forward item in the back-forward list.

Sets Navigation property.

WKWebViewControlMBS.goToBackForwardListItem(Item as WKBackForwardListItemMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Navigates to an item from the back-forward list and sets it as the current item.

item: The item to which to navigate. Must be one of the items in the web view's back-forward list.

Sets Navigation property.

WKWebViewControlMBS.LoadData(Data as MemoryBlock, MIMEType as String, textEncodingName as String, baseURL as string = "")

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 16.4 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Sets the webpage contents and base URL.
Example
Var browser As WKWebViewControlMBS // your instance

browser.LoadData "<p>Hello World</p>", "text/html", "UTF-8", ""

data: The data to use as the contents of the webpage.
MIMEType: The MIME type of the data.
characterEncodingName: The data's character encoding name.
baseURL: A URL used to resolve relative URLs within the document.

Sets Navigation property.

WKWebViewControlMBS.LoadFileURL(File as FolderItem, readAccessItem as FolderItem)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Navigates to a requested file.
Example
Var w as WKWebViewControlMBS // your web viewer
Var HTMLFile as folderItem = getfolderItem("test.html")

// pass folderitem parent to allow read to other files in same folder
w.LoadFileURL HTMLFile, HTMLFile.parent

Navigates to the requested file URL on the filesystem.
file: The file URL to which to navigate.
readAccessItem: The file or folder to allow read access to.
If readAccessItem references a single file, only that file may be loaded by WebKit.
If readAccessItem references a directory, files inside that file may be loaded by WebKit.

Sets Navigation property.

WKWebViewControlMBS.LoadHTML(htmlText as String, baseURL as string = "")

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 16.4 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Sets the webpage contents and base URL.
Example
Var browser As WKWebViewControlMBS // your instance

browser.LoadHTML "<p>Hello World</p>"

htmlText: The string to use as the contents of the webpage.
baseURL: A URL used to resolve relative URLs within the document.

Sets Navigation property.

WKWebViewControlMBS.LoadURL(URL as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 16.4 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Navigates to a requested URL.
Example
Var browser As WKWebViewControlMBS // your instance

call browser.LoadURL "https://www.mbsplugins.de/xojo"

Sets Navigation property.
Sets Navigation property.

WKWebViewControlMBS.LoadURLRequest(Request as NSURLRequestMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 16.4 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Navigates to a requested URL.

Sets Navigation property.

WKWebViewControlMBS.printOperation(printInfo as NSPrintInfoMBS) as NSPrintOperationMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 19.4 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Creates a print operation for the current web viewer.
Example
Var browser as WKWebViewControlMBS // your web viewer
Var pi As NSPrintInfoMBS = NSPrintInfoMBS.sharedPrintInfo
Var po As NSPrintOperationMBS = browser.printOperation(pi)

po.showsPrintPanel = True
po.showsProgressPanel = True

po.runOperationModalForWindow(Self)

Works for WebKit 1.x and 2.x.

For WebKit 2.x may run into endless loop for some websites due to bugs in Apple's WebKit framework.

WKWebViewControlMBS.reload

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 16.4 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Reloads the current page.
Example
Public Sub Reload(browser as WKWebViewControlMBS, force as Boolean)
If force Then
Call browser.reloadFromOrigin
Else
Call browser.reload
End If
End Sub

Sets Navigation property.

WKWebViewControlMBS.reloadFromOrigin

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 16.4 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Reloads the current page, performing end-to-end revalidation using cache-validating conditionals if possible.
Example
Public Sub Reload(browser as WKWebViewControlMBS, force as Boolean)
If force Then
call browser.reloadFromOrigin
Else
call browser.reload
End If
End Sub

Sets Navigation property.

WKWebViewControlMBS.removeAllUserScripts

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 19.5 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Removes all associated user scripts.
Example
Var browser As WKWebViewControlMBS // your instance

browser.removeAllUserScripts

WKWebViewControlMBS.removeScriptMessageHandler(Name as String)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 18.0 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Removes a script message handler.

name: The name of the message handler to remove.

WKWebViewControlMBS.runOpenPanelWithParametersCompleted(URLs() as NSURLMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 22.0 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Pass result for a runOpenPanelWithParameters event here.

Pass nil to indicate cancel was pressed.

WKWebViewControlMBS.setMagnification(magnification as double, pointX as double, pointY as double)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 19.4 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Scales the page content by a specified factor and centers the result on a specified point.
Example
Var browser As WKWebViewControlMBS // your instance

// zoom to 200% on 100/100
browser.setMagnification(2, 100, 100)

magnification: The factor by which to scale the content.
x/y: The point (in view space) to center magnification on. As usual with Cocoa, bottom is y = 0.

For MacOS 64-bit only.

WKWebViewControlMBS.stopLoading

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 16.4 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Stops loading all resources on the current page.
Example
Var browser As WKWebViewControlMBS // your instance

browser.stopLoading

WKWebViewControlMBS.takeSnapshot(byref error as NSErrorMBS) as NSImageMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Requests a snapshot.

This is synchronous version which waits for image to be finished.
In case of error the result is nil and error may be set.

See also:

WKWebViewControlMBS.takeSnapshot(tag as string = "")

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 17.4 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Requests a snapshot.

Calls later takeSnapshotCompleted event.
Tag is passed to event to distinguish various snapshot requests.

See also:

WKWebViewControlMBS.userScripts as WKUserScriptMBS()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 19.5 ✅ Yes ❌ No ❌ No ❌ No Desktop only
The user scripts associated with the user content controller.

The items on this page are in the following plugins: MBS Mac64bit Plugin.


The biggest plugin in space...