次の方法で共有


interface ICoreWebView2Settings

Note

This reference is no longer being maintained. For the latest API reference, see WebView2 API Reference.

interface ICoreWebView2Settings
  : public IUnknown

Defines properties that enable, disable, or modify WebView features.

Summary

Members Descriptions
get_IsScriptEnabled Controls if JavaScript execution is enabled in all future navigations in the WebView.
put_IsScriptEnabled Set the IsScriptEnabled property.
get_IsWebMessageEnabled The IsWebMessageEnabled property is used when loading a new HTML document.
put_IsWebMessageEnabled Set the IsWebMessageEnabled property.
get_AreDefaultScriptDialogsEnabled AreDefaultScriptDialogsEnabled is used when loading a new HTML document.
put_AreDefaultScriptDialogsEnabled Set the AreDefaultScriptDialogsEnabled property.
get_IsStatusBarEnabled IsStatusBarEnabled controls whether the status bar will be displayed.
put_IsStatusBarEnabled Set the IsStatusBarEnabled property.
get_AreDevToolsEnabled AreDevToolsEnabled controls whether the user is able to use the context menu or keyboard shortcuts to open the DevTools window.
put_AreDevToolsEnabled Set the AreDevToolsEnabled property.
get_AreDefaultContextMenusEnabled The AreDefaultContextMenusEnabled property is used to prevent default context menus from being shown to user in webview.
put_AreDefaultContextMenusEnabled Set the AreDefaultContextMenusEnabled property.
get_AreRemoteObjectsAllowed The AreRemoteObjectsAllowed property is used to control whether remote objects are accessible from the page in webview.
put_AreRemoteObjectsAllowed Set the AreRemoteObjectsAllowed property.
get_IsZoomControlEnabled The IsZoomControlEnabled property is used to prevent the user from impacting the zoom of the WebView.
put_IsZoomControlEnabled Set the IsZoomControlEnabled property.

Setting changes made after NavigationStarting event will not apply until the next top level navigation.

Members

get_IsScriptEnabled

Controls if JavaScript execution is enabled in all future navigations in the WebView.

public HRESULT get_IsScriptEnabled(BOOL * isScriptEnabled)

This only affects scripts in the document; scripts injected with ExecuteScript will run even if script is disabled. It is true by default.

        // Changes to settings will apply at the next navigation, which includes the
        // navigation after a NavigationStarting event.  We can use this to change
        // settings according to what site we're visiting.
        if (ShouldBlockScriptForUri(uri.get()))
        {
            m_settings->put_IsScriptEnabled(FALSE);
        }
        else
        {
            m_settings->put_IsScriptEnabled(m_isScriptEnabled);
        }

put_IsScriptEnabled

Set the IsScriptEnabled property.

public HRESULT put_IsScriptEnabled(BOOL isScriptEnabled)

get_IsWebMessageEnabled

The IsWebMessageEnabled property is used when loading a new HTML document.

public HRESULT get_IsWebMessageEnabled(BOOL * isWebMessageEnabled)

If set to true, communication from the host to the webview's top level HTML document is allowed via PostWebMessageAsJson, PostWebMessageAsString, and window.chrome.webview's message event (see PostWebMessageAsJson documentation for details). Communication from the webview's top level HTML document to the host is allowed via window.chrome.webview's postMessage function and the SetWebMessageReceivedEventHandler method (see the SetWebMessageReceivedEventHandler documentation for details). If set to false, then communication is disallowed. PostWebMessageAsJson and PostWebMessageAsString will fail with E_ACCESSDENIED and window.chrome.webview.postMessage will fail by throwing an instance of an Error object. It is true by default.

    ComPtr<ICoreWebView2Settings> settings;
    CHECK_FAILURE(m_webView->get_Settings(&settings));

    CHECK_FAILURE(settings->put_IsWebMessageEnabled(TRUE));

put_IsWebMessageEnabled

Set the IsWebMessageEnabled property.

public HRESULT put_IsWebMessageEnabled(BOOL isWebMessageEnabled)

get_AreDefaultScriptDialogsEnabled

AreDefaultScriptDialogsEnabled is used when loading a new HTML document.

public HRESULT get_AreDefaultScriptDialogsEnabled(BOOL * areDefaultScriptDialogsEnabled)

If set to false, then WebView won't render the default javascript dialog box (Specifically those shown by the javascript alert, confirm, prompt functions and beforeunload event). Instead, if an event handler is set by SetScriptDialogOpeningEventHandler, WebView will send an event that will contain all of the information for the dialog and allow the host app to show its own custom UI.

put_AreDefaultScriptDialogsEnabled

Set the AreDefaultScriptDialogsEnabled property.

public HRESULT put_AreDefaultScriptDialogsEnabled(BOOL areDefaultScriptDialogsEnabled)

get_IsStatusBarEnabled

IsStatusBarEnabled controls whether the status bar will be displayed.

public HRESULT get_IsStatusBarEnabled(BOOL * isStatusBarEnabled)

The status bar is usually displayed in the lower left of the WebView and shows things such as the URI of a link when the user hovers over it and other information. It is true by default.

put_IsStatusBarEnabled

Set the IsStatusBarEnabled property.

public HRESULT put_IsStatusBarEnabled(BOOL isStatusBarEnabled)

get_AreDevToolsEnabled

AreDevToolsEnabled controls whether the user is able to use the context menu or keyboard shortcuts to open the DevTools window.

public HRESULT get_AreDevToolsEnabled(BOOL * areDevToolsEnabled)

It is true by default.

put_AreDevToolsEnabled

Set the AreDevToolsEnabled property.

public HRESULT put_AreDevToolsEnabled(BOOL areDevToolsEnabled)

get_AreDefaultContextMenusEnabled

The AreDefaultContextMenusEnabled property is used to prevent default context menus from being shown to user in webview.

public HRESULT get_AreDefaultContextMenusEnabled(BOOL * enabled)

Defaults to TRUE.

            BOOL allowContextMenus;
            CHECK_FAILURE(m_settings->get_AreDefaultContextMenusEnabled(
                &allowContextMenus));
            if (allowContextMenus) {
                CHECK_FAILURE(m_settings->put_AreDefaultContextMenusEnabled(FALSE));
                MessageBox(nullptr,
                L"Context menus will be disabled after the next navigation.",
                L"Settings change", MB_OK);
            }
            else {
                CHECK_FAILURE(m_settings->put_AreDefaultContextMenusEnabled(TRUE));
                MessageBox(nullptr,
                    L"Context menus will be enabled after the next navigation.",
                    L"Settings change", MB_OK);
            }

put_AreDefaultContextMenusEnabled

Set the AreDefaultContextMenusEnabled property.

public HRESULT put_AreDefaultContextMenusEnabled(BOOL enabled)

get_AreRemoteObjectsAllowed

The AreRemoteObjectsAllowed property is used to control whether remote objects are accessible from the page in webview.

public HRESULT get_AreRemoteObjectsAllowed(BOOL * allowed)

Defaults to TRUE.

            BOOL allowRemoteObjects;
            CHECK_FAILURE(m_settings->get_AreRemoteObjectsAllowed(&allowRemoteObjects));
            if (allowRemoteObjects)
            {
                CHECK_FAILURE(m_settings->put_AreRemoteObjectsAllowed(FALSE));
                MessageBox(
                    nullptr, L"Access to remote objects will be denied after the next navigation.",
                    L"Settings change", MB_OK);
            }
            else
            {
                CHECK_FAILURE(m_settings->put_AreRemoteObjectsAllowed(TRUE));
                MessageBox(
                    nullptr, L"Access to remote objects will be allowed after the next navigation.",
                    L"Settings change", MB_OK);
            }

put_AreRemoteObjectsAllowed

Set the AreRemoteObjectsAllowed property.

public HRESULT put_AreRemoteObjectsAllowed(BOOL allowed)

get_IsZoomControlEnabled

The IsZoomControlEnabled property is used to prevent the user from impacting the zoom of the WebView.

public HRESULT get_IsZoomControlEnabled(BOOL * enabled)

Defaults to TRUE. When disabled, user will not be able to zoom using ctrl+/- or ctrl+mouse wheel, but the zoom can be set via put_ZoomFactor API.

            BOOL zoomControlEnabled;
            CHECK_FAILURE(m_settings->get_IsZoomControlEnabled(&zoomControlEnabled));
            if (zoomControlEnabled)
            {
                CHECK_FAILURE(m_settings->put_IsZoomControlEnabled(FALSE));
                MessageBox(
                    nullptr, L"Zoom control is disabled after the next navigation.", L"Settings change",
                    MB_OK);
            }
            else
            {
                CHECK_FAILURE(m_settings->put_IsZoomControlEnabled(TRUE));
                MessageBox(
                    nullptr, L"Zoom control is enabled after the next navigation.", L"Settings change",
                    MB_OK);
            }

put_IsZoomControlEnabled

Set the IsZoomControlEnabled property.

public HRESULT put_IsZoomControlEnabled(BOOL enabled)