次の方法で共有


SP へClientContext コンス (sp.js)

指定した SharePoint サイトのClientContextオブジェクトの新しいインスタンスを初期化します。

**適用対象:**apps for SharePoint | SharePoint Foundation 2013 | SharePoint Server 2013

var object = new SP.ClientContext(serverRelativeUrlOrFullUrl)

パラメーター

  • serverRelativeUrlOrFullUrl
    /で始まる相対 URL またはhttp://またはhttps://で始まる完全な URL です。

戻り値

SP へClientContext
、指定した SharePoint サイト、クライアントのコンテキストの新しいインスタンスします。

次の例では、指定された URL のクライアントのコンテキストを取得します。

注意

コードを実行する前に、 url変数のプレース ホルダーの値を変更します。

var url = 'replace with server-relative or absolute URL';
var clientContext;
var website;

// Make sure the SharePoint script file 'sp.js' is loaded before your
// code runs.
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);

// Create an instance of the client context for the specified URL.
function sharePointReady() {
    clientContext = new SP.ClientContext(url);
    website = clientContext.get_web();

    clientContext.load(website);
    clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed);
}
function onRequestSucceeded() {
    alert('URL of the website: ' + website.get_url());
}
function onRequestFailed(sender, args) {
    alert('Error: ' + args.get_message());
}

関連項目

その他の技術情報

SP へClientContext オブジェクト (sp.js)