Method XbpHTMLViewer2():setSettings() Foundation

Configures the internal WebView2 component.

Syntax
:setSettings( <oSettings> ) --> lSuccess
Parameters
<oSettings>
A CoreWebView2Settings object with the desired settings.
Return

.T. (true) if the specified settings were set, .F. (false) otherwise.

Description

Various settings of the internal WebView2 component can be changed by directly specifying native options via :setSettings(). This is done via a CoreWebView2Settings object which exposes various WebView2-specific options via its member variables.

The changes will take effect the next time a navigation is initiated using :navigate(). An arbitrary number of settings objects can be created for parameterizing individual navigation requests.

Note that :setSettings() can only be used after the html viewer object was created. Otherwise, a runtime error is generated.

Example for using :setSettings() to change WebView2-specific settings

// This example demonstrates using :setSettings() for disabling 
// the default context menu with standard commands for printing 
// or saving the HTML content to a file. This is a common 
// use-case, for example, for preventing the user from performing 
// commands that are a part of the application workflow. In 
// addition, the example enables opening the development console 
// by pressing the F12 key which is often required for debugging. 
#include "xbp.ch" 

PROCEDURE Main() 
LOCAL oDlg 
LOCAL oViewer2 
LOCAL oSettings 

  SET CHARSET TO ANSI 

  // Create a form for hosting the HTML viewer object 
  oDlg := XbpDialog():new( AppDesktop() ) 
  oDlg:taskList := .T. 
  oDlg:title    := "XbpHTMLViewer2:setSettings() example" 
  oDlg:create( ,,, {640,480} ) 
  CenterControl( oDlg ) 

  // Create the HTML viewer object in the form's content area 
  oViewer2 := XbpHTMLViewer2():new( oDlg:drawingArea ) 
  oViewer2:layoutAlign := XBPLAYOUT_LEFT + XBPLAYOUT_TOP + XBPLAYOUT_RIGHT + XBPLAYOUT_BOTTOM 
  oViewer2:create( ,, {10,10}, {600,420} ) 

  // Disable the default context menu and allow opening the 
  // development tools console via the F12 key 
  oSettings := CoreWebView2Settings():new() 
  oSettings:areDefaultContextMenusEnabled := .F. 
  oSettings:areDevToolsEnabled := .T. 
  oViewer2:setSettings( oSettings ) 

  // Navigate to a webpage. Navigation occurs asynchronously. 
  // Use the :wait() method of the returned AsyncResult object 
  // to wait for navigation to complete 
  oViewer2:navigate( "https://www.alaska-software.com" ) 

  oDlg:showModal() 
  oDlg:destroy() 
RETURN 

PROCEDURE AppSys() 
  // Prevent creation of the default console window 
RETURN 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.