SharePoint 2020

The Vision for a Future of Clarity

Add Button to web part to Open any address in Dialog box

This is a script that you can use for SharePoint 2010 (untested in SharePoint 2013)

I currently use this script to open a list item’s NewForm.aspx page.

But you can use it to display and web address in a pop-up dialog.

And no JQuery is required!

Added notifications, if Ok or Cancel buttons clicked in the dialog.

Open Link button

dialog windows

Any URL can be displayed in Dialog

To test it out, just add this code to a txt or html file and link it to a Content Editor Web Part

<script type="text/javascript">

function portal_openModalDialog() {
var options = SP.UI.$create_DialogOptions();
options.url = "/_layouts/Upload.aspx?List={327D2CF7-F385-4969-8973-E6FD3908A996}&RootFolder="; //Change the URL to the page you require.
options.title = "Title of Dialog Window";
options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
SP.UI.ModalDialog.showModalDialog(options);
}
function CloseCallback(result, value) {
if (result === SP.UI.DialogResult.OK) {
SP.UI.Notify.addNotification("Your request has been submitted");
}
if (result === SP.UI.DialogResult.cancel) {
SP.UI.Notify.addNotification("Request cancelled");
}
}
</script>

<button name="button" type="button" onclick="javascript:portal_openModalDialog();javascript:return false;" href="#" target="_self">Open Link</button>

Pastebin Version: http://pastebin.com/mfmQLUCX (opens in new tab)
Advertisements

May 3, 2016 Posted by | SharePoint 2010, SharePoint Javascript | , | Leave a comment