Class (WebContextMenuParam)

Implements a WebContextMenuParam object, which is displayed after the user clicks the right mouse button or long presses a specific element, such as an image or a link. For details about the sample code, see onContextMenuShow.

NOTE

  • The initial APIs of this component are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.

  • The initial APIs of this class are supported since API version 9.

  • The sample effect is subject to the actual device.

constructor9+

constructor()

Constructs a WebContextMenuParam object.

System capability: SystemCapability.Web.Webview.Core

x9+

x(): number

Obtains the X coordinate of the context menu.

System capability: SystemCapability.Web.Webview.Core

Return value

Type Description
number If the display is normal, a non-negative integer is returned. Otherwise, -1 is returned.
Unit: px (physical pixel)

y9+

y(): number

Obtains the Y coordinate of the context menu.

System capability: SystemCapability.Web.Webview.Core

Return value

Type Description
number If the display is normal, a non-negative integer is returned. Otherwise, -1 is returned.
Unit: px (physical pixel)

getLinkUrl9+

getLinkUrl(): string

Obtains the URL that has passed the security check.

System capability: SystemCapability.Web.Webview.Core

Return value

Type Description
string If it is a link that is being long pressed, the URL that has passed the security check is returned.

getUnfilteredLinkUrl9+

getUnfilteredLinkUrl(): string

Obtains the original URL.

System capability: SystemCapability.Web.Webview.Core

Return value

Type Description
string If it is a link that is being long pressed, the original URL is returned.

getSourceUrl9+

getSourceUrl(): string

Obtains the source URL.

System capability: SystemCapability.Web.Webview.Core

Return value

Type Description
string If the selected element has the src attribute, the URL in the src is returned. The maximum size of the returned URL is 2 MB. If the size exceeds the upper limit, an empty string is returned.

existsImageContents9+

existsImageContents(): boolean

Checks whether image content exists.

System capability: SystemCapability.Web.Webview.Core

Return value

Type Description
boolean The value true means that there is image content in the element being long pressed, and false means the opposite.

getMediaType9+

getMediaType(): ContextMenuMediaType

Obtains the media type of this web page element.

System capability: SystemCapability.Web.Webview.Core

Return value

Type Description
ContextMenuMediaType Media type of the web page element.

getSelectionText9+

getSelectionText(): string

Obtains the selected text.

System capability: SystemCapability.Web.Webview.Core

Return value

Type Description
string Selected text for the context menu. If no text is selected, null is returned.

getSourceType9+

getSourceType(): ContextMenuSourceType

Obtains the event source of the context menu.

System capability: SystemCapability.Web.Webview.Core

Return value

Type Description
ContextMenuSourceType Event source of the context menu.

getInputFieldType9+

getInputFieldType(): ContextMenuInputFieldType

Obtains the input field type of this web page element.

System capability: SystemCapability.Web.Webview.Core

Return value

Type Description
ContextMenuInputFieldType Input field type.

isEditable9+

isEditable(): boolean

Checks whether a web page element is editable.

System capability: SystemCapability.Web.Webview.Core

Return value

Type Description
boolean true is returned if the web page element is editable; otherwise, false is returned.

getEditStateFlags9+

getEditStateFlags(): number

Obtains the edit state flag of this web page element.

System capability: SystemCapability.Web.Webview.Core

Return value

Type Description
number Edit state flag of the web page element. For details, see ContextMenuEditStateFlags.

getPreviewWidth13+

getPreviewWidth(): number

Obtains the width of a preview image.

System capability: SystemCapability.Web.Webview.Core

Return value

Type Description
number Width of a preview image.
Unit: px (physical pixel)

getPreviewHeight13+

getPreviewHeight(): number

Obtains the height of a preview image.

System capability: SystemCapability.Web.Webview.Core

Return value

Type Description
number Height of a preview image.
Unit: px (physical pixel)

getContextMenuMediaType22+

getContextMenuMediaType(): ContextMenuDataMediaType

Obtains the type of the web page element that the user taps when the context menu event is reported.

System capability: SystemCapability.Web.Webview.Core

Return value

Type Description
ContextMenuDataMediaType Media type of the web page element.