- Qt 6.9
- Qt WebEngine
- QML Types
- JavaScriptDialogRequest
- Qt 6.9.0 Reference Documentation

# JavaScriptDialogRequest QML Type

A request for showing an alert, a confirmation, or a prompt dialog from within JavaScript to the user. More...

Import Statement: | `import QtWebEngine`
Since: | QtWebEngine 1.4

- List of all members, including inherited members

## Properties

- accepted : bool
- defaultText : string
- message : string
- securityOrigin : url
- title : string
- type : enumeration

## Methods

- void dialogAccept()
- void dialogAccept(string text)
- void dialogReject()

## Detailed Description

A JavaScriptDialogRequest is passed as an argument of the WebEngineView::javaScriptDialogRequested signal. The request is emitted if JavaScript on the page calls HTML5's Simple Dialogs API, or in response to HTML5's BeforeUnloadEvent. The type of a particular dialog can be checked with the type property.

The accepted property of the request indicates whether the request is handled by the user code or the default dialog should be displayed. If you set the accepted property to `true`, make sure to call either dialogAccept() or dialogReject() afterwards. The JavaScript call causing the request will be blocked until then.

The following code uses a custom dialog to handle the request:

     WebEngineView {
         // ...
         onJavaScriptDialogRequested: function(request) {
             request.accepted = true;
             myDialog.request = request // keep the reference to the request
             myDialog.accept.connect(request.dialogAccept);
             myDialog.reject.connect(request.dialogReject);
             myDialog.visible = true;
         }
         // ...
     }

## Property Documentation

accepted : bool

Indicates whether the JavaScript dialog request has been accepted by the signal handler.

If the property is `false` after any signal handlers for WebEngineView::javaScriptDialogRequested have been executed, a default dialog will be shown. To prevent this, set `request.accepted` to `true`.

The default is `false`.

defaultText : string `[read-only]`

The default prompt text, if the requested dialog is a prompt.

message : string `[read-only]`

The message to be shown to the user.

securityOrigin : url `[read-only]`

The URL of the security origin.

title : string `[read-only]`

A default title for the dialog.

type : enumeration `[read-only]`

Returns the type of the requested dialog box. For more information, see HTML5's Simple Dialogs.

Constant | Description
--- | ---
`JavaScriptDialogRequest.DialogTypeAlert` | A JavaScript alert dialog.
`JavaScriptDialogRequest.DialogTypeConfirm` | A JavaScript confirmation dialog.
`JavaScriptDialogRequest.DialogTypePrompt` | A JavaScript prompt dialog.
`JavaScriptDialogRequest.DialogTypeBeforeUnload` | The users should be asked if they want to leave the page.

## Method Documentation

void dialogAccept()

This function notifies the engine that the user accepted the dialog.

void dialogAccept(string text)

This function notifies the engine that the user accepted the dialog, providing the text in case of a prompt message box.

void dialogReject()

This function notifies the engine that the user rejected the dialog.