Solved

Link to SharePoint 2010 NewForm in modal dialog from regular site

Posted on 2016-11-23
4
22 Views
Last Modified: 2016-11-25
I have a regular site that has a button that has link to NewForm of SP 2010 list. I need NewForm to open in modal dialog and then after submitting data to redirect to Thank you page in modal dialog too.
I tried old java script window.showModalDialog (see below) but it does not work in Chrome.
<script type="text/javascript">

    function fnRandom(iModifier) {
        return parseInt(Math.random() * iModifier);
    }

 
    function fnOpen() {
        
        window.showModalDialog("/NewForm.aspx", "", "dialogWidth:900px; dialogHeight:600px")
    }
      </script>

Open in new window


For redirecting from NewForm to thanks page I use
 onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={/Thankyou.aspx}')}"
it works but does not open it in modal dialog.
I tried to add IsDlg=1 but it does not open it in dialog.
Please help
0
Comment
Question by:LessIsMore
  • 2
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 41900007
just use window.open if window.showModalDialog is not available :

<script type="text/javascript">
    function fnRandom(iModifier) {
        return parseInt(Math.random() * iModifier);
    }

    function fnOpen() {
        if(window.showModalDialog)    
             window.showModalDialog("/NewForm.aspx", "", "dialogWidth:900px; dialogHeight:600px")
        else {
             var w = window.open("/NewForm.aspx", "", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=900, height=600, top=300, left=510");
             w.focus();
        }
    }
</script>

Open in new window


more general, you can emulate it if you call it more than one time :
https://kapilakhia.wordpress.com/tag/window-showmodaldialog/
https://gist.github.com/fhferreira/b8d92a3062881daeaec9

// fix for deprecated method in Chrome 37
  if (!window.showModalDialog) {
     window.showModalDialog = function (arg1, arg2, arg3) {

        var w;
        var h;
        var resizable = "no";
        var scroll = "no";
        var status = "no";

        // get the modal specs
        var mdattrs = arg3.split(";");
        for (i = 0; i < mdattrs.length; i++) {
           var mdattr = mdattrs[i].split(":");

           var n = mdattr[0];
           var v = mdattr[1];
           if (n) { n = n.trim().toLowerCase(); }
           if (v) { v = v.trim().toLowerCase(); }

           if (n == "dialogheight") {
              h = v.replace("px", "");
           } else if (n == "dialogwidth") {
              w = v.replace("px", "");
           } else if (n == "resizable") {
              resizable = v;
           } else if (n == "scroll") {
              scroll = v;
           } else if (n == "status") {
              status = v;
           }
        }

        var left = window.screenX + (window.outerWidth / 2) - (w / 2);
        var top = window.screenY + (window.outerHeight / 2) - (h / 2);
        var targetWin = window.open(arg1, arg1, 'toolbar=no, location=no, directories=no, status=' + status + ', menubar=no, scrollbars=' + scroll + ', resizable=' + resizable + ', copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
        targetWin.focus();
     };
  }

Open in new window

0
 

Author Comment

by:LessIsMore
ID: 41902018
Leakim975,
Thanks for your help! I used first script and it works fine. Maybe you can help me with second part of my question?

For redirecting from NewForm to thanks page on Submit button I use
 onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={/Thankyou.aspx}')}"

it redirects but does not open it in modal dialog. I would like it to be open in the same window as previous page.
I tried to add IsDlg=1 but it does not open it in dialog.

Maybe I can add the same script but cannot figure out where to place it in the onclick event?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 41902021
yes, it's better to create this as a new question, thanks
0
 

Author Closing Comment

by:LessIsMore
ID: 41902098
Thanks, it works!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now