Is Javascript supported in Content Editor WebPart (CEW) of SharePoint 2013 Preview ?

Locked Is Javascript supported in Content Editor WebPart (CEW) of SharePoint 2013 Preview ?

  • Monday, August 06, 2012 4:56 PM
     
     

    The java script function of opening a dialog from content editor webpart stoped working after upgrade to SharePoint 2013 Preview.

    Is Javascript supported in Content Editor WebPart (CEW) of SharePoint 2013 Preview ?


    Villpates

All Replies

  • Tuesday, August 07, 2012 12:41 PM
     
     
    I cannot say whether it is officially supported but I just added a part to a page and added an alert via javascript.  It came up just fine.  Can you post the code?  Have you checked the rendered HTML and for browser errors? 

    -James
    MCPD: SharePoint Developer 2010
    Posting is provided "AS IS" with no warranties, and confers no rights.
    Please mark as answer or helpful as appropriate

  • Tuesday, August 07, 2012 1:15 PM
     
     
    Yes.Sharepoint 2013 preview version is supporting the javascript inside content editor webpart .Please check your code .Try to add simple alert script in your page to sort out your issue,before adding your script ..
  • Monday, August 13, 2012 10:14 AM
     
     

    Hi,

    I have below mentioned script working fine in CEW of SharePoint 2010 environment.

    <script type="text/javascript">     
     function OpenDialog(URL)
     {
             var NewPopUp = SP.UI.$create_DialogOptions();
             NewPopUp.url = URL;
      allowMaximize: true;
      showClose: true;
             NewPopUp.dialogReturnValueCallback = refreshCallback;
             SP.UI.ModalDialog.showModalDialog(NewPopUp);
          }

         function refreshCallback(dialogResult, returnValue)
     {
          SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
          }
    </script>
    <a href="javascript:OpenDialog(&#39;../_layouts/Upload.aspx?List={EC310F12-F720-436C-BD20-B5FB19D45DEC}&#39;)">

    But as soon as I copy this script in the CEW of the SharPoint 2013 Preview environment both of the above 2 functions disappears and hence it give javascript error.

    By these java script function I am opening default upload page of document library and doing a refresh after upload gets completed.


    Vipul Patel - Villpates http://villpates.wordpress.com/ http://villpates.blogspot.com/

  • Monday, August 13, 2012 12:00 PM
     
     

    Hi Vipul,

    Take a look at this:

    http://msdn.microsoft.com/en-us/library/jj163201(v=office.15).aspx


    Regards
    Henrik A. Halmstrand
    sharepointrevealed.com
    getspconfig.codeplex.com
    Please click Mark As Answer; if a post solves your problem or Vote As Helpful; if a post has been useful to you.

  • Monday, August 13, 2012 2:53 PM
     
     

    When I add your code directly in the page it displays a message telling me that it has removed the code and to try the "EMBED" command but I do not think that would work.  So, I saved the code to a file, uploaded it to a doc lib and referenced it from the CEWP property "Content Link".  It works like a charm! (With a different GUID of course)


    -James
    MCPD: SharePoint Developer 2010
    Posting is provided "AS IS" with no warranties, and confers no rights.
    Please mark as answer or helpful as appropriate

  • Monday, August 13, 2012 2:54 PM
     
     
    BTW - I saved the file as .txt (not HTM or JS)

    -James
    MCPD: SharePoint Developer 2010
    Posting is provided "AS IS" with no warranties, and confers no rights.
    Please mark as answer or helpful as appropriate

  • Tuesday, August 14, 2012 9:09 AM
     
     

    Hi All,

    Forgot to  mention that mine is a publishing page. Javascript is working fine in either case (directly in the HTML Source and CEW Content Link) when the page is in draft mode. As soon as the page is published it starts giving java script error. Wiered...


    Vipul Patel - Villpates http://villpates.wordpress.com/ http://villpates.blogspot.com/

  • Thursday, September 27, 2012 8:30 PM
     
      Has Code

    In SharePoint 2013, the standard way to embed a script would be the Script Editor Web Part, rather than a Content Editor Web Part.

    When a script is pasted directly in a Content Editor Web Part, SharePoint performs a cleanup and you might lose some or all of your code. This is not specific to 2013 and also happened in SP 2010. A workaround is to store the code is a separate txt file and link to it from the CEWP (as described by James Yarnell). The separate txt file also makes your code reusable. More details here:

    http://blog.pathtosharepoint.com/2010/10/27/about-scripts-web-parts-and-urban-myths/

    Another approach you can try, if you really want an embedded script, is to wrap your code in a CDATA section:

    <script type="text/javascript">
    //<![CDATA[
    ...code...
    //]]>
    </script>

    One more option: use a Form Web Part.

    There are still other ways, but I'll stop here for now :-)


    Christophe Humbert Path to SharePoint http://blog.PathToSharePoint.com User Managed Solutions http://UserManagedSolutions.com