I've created a sharepoint hosted app. Then I deleted Default.aspx and create Home.html. In app.js I can't see _spPageContextInfo. Is there any one can show me how to fix it but not reuse Defaul.aspx . I don't know what js library I should add to html page and how to add it. Thanks.


You need the ASP directives like the default page uses in order to have _spPageContextInfo object load -- and you also need the containers the default page uses otherwise the page won't load correctly either...

Here is really the minimum amount of markup you need for a SharePoint App page if you want it to interact properly with the underlying SharePoint infrastructure (such as using _spPageContextInfo, or permissions, or many other things SharePoint provides) modified from the boilerplate app default page in the Napa developer tools -- if it's a comment you can delete it, I'm just demonstrating where you should put stuff:

EDIT: Woops -- apparently did not space my markup correctly for the ASP directives up top, you should see them all now though.

<%@ Page Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" MasterPageFile="~masterurl/default.master" Language="C#" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%-- The markup and script in the following Content element will be placed in the <head> of the page --%>
<asp:Content ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
    <!-- I really recommend the next 3 lines be uncommented, but you don't strictly need them...
    <script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
    <script type="text/javascript" src="/_layouts/15/sp.js"></script>
    <!-- Add your CSS reference link here -->
    <!-- Add your custom JS script references here -->

<%-- The markup in the following Content element will be placed in the TitleArea of the page --%>
<asp:Content ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server">
    <!--Page Title-->

<%-- The markup and script in the following Content element will be placed in the <body> of the page --%>
<asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <!--Your html content for the body tag goes in here, but don't add your own body tag...-->
  • problem is. I'm using chrome control and follow some tutorial online, they are delete a Default.aspx and create new Home.html. So Is there any way to solve this? . or can I use chrome control without create a Home.html – user3622351 Aug 28 '14 at 1:45
  • I've follow but when I'm trying to alert(url) url = _spPageContextInfo.WebAbsoluteUrl. It alert undefine – user3622351 Aug 28 '14 at 2:20
  • It might be an issue of not waiting for the page to finish before trying to use the object. After the page loads, if you open the dev tools and type in '_spPageContextInfo' into the JavaScript console, does it give you an object with information in it or undefined? – John-M Aug 28 '14 at 2:45
  • NO, in console I can alert(url) using _spPageContextInfo as normal, but in app.js it's undefined. – user3622351 Aug 28 '14 at 2:49
  • Checked two methods to deal with what it seems like you're talking about: either put your reference to app.js at the bottom of the PlaceHolderMain content area, or wrap your alert inside of jQuery.ready – John-M Aug 28 '14 at 3:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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