Solved

Link to SharePoint 2010 NewForm in modal dialog from regular site

Posted on 2016-11-23
4
42 Views
Last Modified: 2016-12-21
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

896 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

19 Experts available now in Live!

Get 1:1 Help Now