如何使用javascript打开Sharepoint模式对话框以提示用户输入(How to use javascript to open up a Sharepoint Modal Dialog to

编程入门 行业动态 更新时间:2024-10-25 04:16:36
如何使用javascript打开Sharepoint模式对话框以提示用户输入(How to use javascript to open up a Sharepoint Modal Dialog to prompt user for input)

我正在尝试使用一些JavaScript来打开SharePoint模式对话框以提示用户输入,然后将该值存储到变量中。 有谁知道如何做到这一点? 我正在为Nintex任务表单执行此操作。

I am trying to use some JavaScript to open up a SharePoint Modal Dialog to prompt the user for input and then store that value into a variable. Does anyone know how to do this? I am doing this for a Nintex task form.

最满意答案

你试过什么了? 最简单的选择是利用SP.UI.ModalDialog类,该类提供打开本机SP模式的方法 - 您可以通过URL参数加载单独的页面(ASPX,HTML等)或直接将HTML传递给模式渲染。

无论采用哪种方法,您的标记都可以包含<input>以捕获用户的值,并随附JS以将输入值存储在任何您想要的位置(包括在变量中)。

根据您正在使用的其他JS(如果有)或如何设置页面,您可能还需要利用SP2013的“脚本按需”(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; }

What have you tried so far? The simplest option would be to leverage the SP.UI.ModalDialog class which provides methods for opening a native SP modal - you can load either a separate page (ASPX, HTML, etc) via URL parameter or pass HTML directly to the modal to be rendered.

With either approach, your markup could then include an <input> to capture the value from the user and accompanying JS to store the input value wherever you want (including in a variable).

Depending on what other JS you're using (if any) or how the page is setup, you may also need to leverage SP2013's "Script On Demand" (SOD) function to ensure the necessary JS for the SP Modal is loaded.

Here's a simple example:

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; }

更多推荐

本文发布于:2023-07-23 00:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1225132.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   对话框   提示   模式   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!