Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I would like to use the SharePoint Javascript Object Model from a "plain" html page (ie, not an .aspx application page etc.) Is this even possible? If so, what scripts should I reference? I've added the following:

  <script type="text/ecmascript" src="/_layouts/SP.js" />
  <script type="text/ecmascript" src="/_layouts/SP.Core.js" />
  <script type="text/ecmascript" src="/_layouts/SP.Debug.js" />
  <script type="text/ecmascript" src="/_layouts/SP.Runtime.Debug.js" />

But when the page loads, I get a 'Type is not defined' error in SP.js and SP.Core.js. Note this is from within the SP site, so this isn't a cross-domain issue.

share|improve this question
    
Where have you hosted the html file? Under \\-<hive>-\Layouts ? If it's just uploaded to a doc library, try using full path of the site e.g. intranet.mycompany.com/sites/testsite/_layouts/SP.js –  sumitkm Oct 21 '11 at 8:18
add comment

3 Answers

up vote 3 down vote accepted

The SharePoint JavaScript client object model only works on pages that are a part of the SharePoint framework (i.e. in Web Parts, Application Pages, etc.). This tutorial makes mention of that: http://www.codeproject.com/Articles/60348/SharePoint-2010-Client-Object-Model-for-JavaScript.aspx

share|improve this answer
    
You could, however, write a custom REST or AJAX web service that does the calls for you and then you could access those from your JavaScript. –  John Chapman Nov 6 '11 at 1:08
    
I actually got it 'almost working', but SP.js definitely depends on some markup and other scripts only found in application pages. REST and Ajax against the built-in listdata.svc, etc. is what I landed on, though I'm not sure I'll be able to get at everything I would have liked (like SPWeb.Navigation). –  Daniel Nov 7 '11 at 2:34
add comment

This is what I used to fix this problem:

<SharePoint:ScriptLink Name="MicrosoftAjax.js" runat="server" Defer="False" Localizable="false"/>
<SharePoint:ScriptLink Name="SP.core.js" runat="server" Defer="False" Localizable="false"/>
<SharePoint:ScriptLink Name="SP.js" runat="server" Defer="True" Localizable="false"/>

I added the above ScriptLinks in this order, and defered both the MicrosoftAjax.js and SP.Core.js includes, and delayed the SP.js. The SP.js file has dependencies in the preceding includes that requires it to be delayed.

share|improve this answer
    
this would not work on a plain html page, just a .aspx –  Daniel Mar 27 at 19:54
add comment
<SharePoint:ScriptLink Name="SP.js" runat="server" OnDemand="true" Localizable="false" />

will do the work.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.