Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Link to SharePoint 2010 NewForm in modal dialog from regular site

Posted on 2016-11-23
4
Medium Priority
?
124 Views
Last Modified: 2017-01-31
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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…

610 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