Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Salesforce open Simple Dialog in custom button/link or on a visualforce page
// if you want to use it inside a visualforce page create a function around it
function showFollowUp() {
// if you want to use it in a button make sure you require jQuery
// {!REQUIRESCRIPT("https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js")} // UNCOMMENT IF IN A BUTTON
// get the dialog with your dialog name
var d = sfdcPage.dialogs['MyCoolDialog'], close;
if (!d) {
// if the dialog doesn't exist create one
d = sfdcPage.dialogs['MyCoolDialog'] = new SimpleDialog('MyCoolDialog', false);
// set general information on your dialog and finally run the create function
d.setTitle('Vorgang auf Wiedervorlage');
d.setWidth(600);
d.createDialog();
}
// give your dialog some content (I usually use an iframe linking to another visualforce page
// change the url, height, width to your needs
$(d.dialog).find('#MyCoolDialogInner').html('<iframe src="/apex/mydialog" height="375" width="565" border="0" style="border: 0;" />');
// once the iframe is loaded you may want to give it some functionality
$(d.dialog).find('#MyCoolDialogInner iframe').on('load', function() {
// find the input boxes within the iframe and attach a click handler
$(this).contents().find('input[type="submit"]').on('click', function() {
// if it is a cancel button close the dialog
if ($(this).val() == 'Cancel') d.hide();
return false;
});
});
// we also need to make sure we have a close button on the dialog
if ($(d.dialog).find('#InlineEditDialogX').size() == 0) {
// if there is none we create it
close = $('<a id="InlineEditDialogX" title="Close" tabindex="0" href="javascript:void(0)" class="dialogClose">Close</a>');
// add some functionality to the close button (for the default ui we change the classname on mouseover/out
close.mouseover(function() {
this.className = 'dialogCloseOn';
}).mouseout(function() {
this.className = 'dialogClose';
}).click(function() {
// finally our on click handler which closes the dialog
d.hide();
});
// insert the new generated close button before the h2 tag so it'll show up on the top right corner
close.insertBefore($(d.dialog).find('.topLeft h2'));
}
// now it's time to show the new dialog
d.show();
}
@Sanjivani

This comment has been minimized.

Copy link

@Sanjivani Sanjivani commented Mar 9, 2014

Is there any way to change background colour of title bar?

@hpmohan

This comment has been minimized.

Copy link

@hpmohan hpmohan commented Jan 3, 2016

In chrome, I am getting 'Uncaught SecurityError: Blocked a frame with origin "https://c.cs5.visual.force.com" from accessing a frame .................................' when trying to access a VF page in iFrame, upon clicking a custom JS button on case detail page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment