Special thanks to the valuable insights provided by Isabel Inc and Mistalis, which resulted in a successful solution.
Here are some key points regarding my unique approach:
- I have made the images within the messages responsive by incorporating relevant Bootstrap classes for each image.
- The messages may contain links, and clicking on a link is treated as equivalent to clicking "OK" on the dialog.
Now, let's delve into the JavaScript code that brings this functionality to life...
jQuery(function($, window, bootbox, undefined) {
var accept = function(callback) {
$.ajax({
type: 'POST',
data: {message_id: 244826},
success: callback()
});
};
var $message = $('<p><img src="https://www.gravatar.com/avatar/80fa81938a6d1df92cd101d7fe997a71" alt></p><p>Here is a message from <a href="https://stackoverflow.com/users/244826/sonny">Sonny</a>.</p>');
$message.find('img').addClass('img-responsive center-block');
$message.find('a').on('click', function(e) {
var href = $(this).attr('href');
if (0 === href.length) {
return;
}
e.preventDefault();
accept(function() { window.location.href = href; });
});
bootbox.dialog({
message: $message,
closeButton: false,
buttons: {
accept: {
label: 'OK',
callback: function() {
accept(function() { window.location.reload(); });
}
}
}
});
}(jQuery, window, bootbox));