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.
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.
constructor()
Constructs a WebContextMenuParam object.
System capability: SystemCapability.Web.Webview.Core
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) |
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) |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |