You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a metabox the content of it is sandboxed. If this metabox contains a button that when clicked it asks for a user confirmation using the Window confirm() method, a JS error is thrown stating that:
Ignored call to 'confirm()'. The document is sandboxed, and the 'allow-modals' keyword is not set.
On the test code below, I'm adding the custom metabox, which contains a button. Then I'm enqueuing a small JS script that handles the click of that button and asks for the user confirmation.
Test code
add_action( 'admin_head', 'my_meta_box' );
function my_meta_box() {
global $post;
add_meta_box(
'my_meta_box',
__( 'My metabox', 'my-context' ),
'my_meta_box_callback',
$post->post_type, 'side'
);
}
function my_meta_box_callback() {
echo '<p>Lorem ipsum dolor sit amet.</p>';
echo '<button type="button" class="js-click-class">Click Me!</button>';
}
add_action( 'admin_footer', 'custom_admin_js' );
function custom_admin_js() {
$script = '
jQuery(".js-click-class").on("click", function () {
confirm( "Are you sure you want to continue?" );
});
';
echo '<script type="text/javascript">' . $script . '</script>';
}
The text was updated successfully, but these errors were encountered:
When creating a metabox the content of it is sandboxed. If this metabox contains a button that when clicked it asks for a user confirmation using the Window confirm() method, a JS error is thrown stating that:
Ignored call to 'confirm()'. The document is sandboxed, and the 'allow-modals' keyword is not set.
On the test code below, I'm adding the custom metabox, which contains a button. Then I'm enqueuing a small JS script that handles the click of that button and asks for the user confirmation.
Test code
The text was updated successfully, but these errors were encountered: