如何使用 javascript 打开 Sharepoint 模式对话框提示用户输入
How to use javascript to open up a Sharepoint Modal Dialog to prompt user for input
我正在尝试使用一些 JavaScript 打开 SharePoint 模式对话框以提示用户输入,然后将该值存储到变量中。有谁知道如何做到这一点?我正在为 Nintex 任务表单执行此操作。
到目前为止你尝试了什么?最简单的选择是利用 SP.UI.ModalDialog class,它提供了打开本机 SP 模式的方法 - 您可以通过 [=25 加载单独的页面(ASPX、HTML 等) =] 参数或将 HTML 直接传递给要渲染的模态。
无论使用哪种方法,您的标记都可以包含一个 <input>
来捕获用户的值,并随附 JS 以将输入值存储在您想要的任何位置(包括在变量中)。
根据您使用的其他 JS(如果有)或页面设置方式,您可能还需要利用 SP2013 的 "Script On Demand" (SOD) 功能来确保 SP 模态所需的 JS已加载。
这是一个简单的例子:
function OpenMyModal(SomeVar) {
// If using inline HTML, first create a parent element...
var MyHtmlElement = document.createElement('div');
// ... then populate it
MyHtmlElement.innerHTML = '<input... />';
// Define the Modal's options
var options = {
// define a URL (and yes, you can pass params to that URL) or reference your HTML object, but NOT both!
url: '../MyPage.aspx?MyParam=' + SomeVar + '&IsDlg=1',
// html: MyHtmlElement,
tite: 'Modal Title',
allowMaximize: false,
showClose: true,
width: 430,
height: 230
};
// This ensures the supporting JS needed is loaded on the page
SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
return false;
}
我正在尝试使用一些 JavaScript 打开 SharePoint 模式对话框以提示用户输入,然后将该值存储到变量中。有谁知道如何做到这一点?我正在为 Nintex 任务表单执行此操作。
到目前为止你尝试了什么?最简单的选择是利用 SP.UI.ModalDialog class,它提供了打开本机 SP 模式的方法 - 您可以通过 [=25 加载单独的页面(ASPX、HTML 等) =] 参数或将 HTML 直接传递给要渲染的模态。
无论使用哪种方法,您的标记都可以包含一个 <input>
来捕获用户的值,并随附 JS 以将输入值存储在您想要的任何位置(包括在变量中)。
根据您使用的其他 JS(如果有)或页面设置方式,您可能还需要利用 SP2013 的 "Script On Demand" (SOD) 功能来确保 SP 模态所需的 JS已加载。
这是一个简单的例子:
function OpenMyModal(SomeVar) {
// If using inline HTML, first create a parent element...
var MyHtmlElement = document.createElement('div');
// ... then populate it
MyHtmlElement.innerHTML = '<input... />';
// Define the Modal's options
var options = {
// define a URL (and yes, you can pass params to that URL) or reference your HTML object, but NOT both!
url: '../MyPage.aspx?MyParam=' + SomeVar + '&IsDlg=1',
// html: MyHtmlElement,
tite: 'Modal Title',
allowMaximize: false,
showClose: true,
width: 430,
height: 230
};
// This ensures the supporting JS needed is loaded on the page
SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
return false;
}