javascript 使用 URL 获取 ClientContext
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21432746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get ClientContext using URL
提问by Ravi Verma
In Sharepoint, when we load the sp.js file after that when we use given code then it gives the current site context. But how can i get the site context using url.
在 Sharepoint 中,当我们在使用给定代码之后加载 sp.js 文件时,它会提供当前站点上下文。但是如何使用 url 获取站点上下文。
var context = new SP.ClientContext.get_current();
回答by Arvind
get_current()
would always return current context only. If you want to get context of particular site then you would need to pass url in ClientContext()
method.
get_current()
将始终仅返回当前上下文。如果您想获取特定站点的上下文,则需要在ClientContext()
方法中传递 url 。
var context = new SP.ClientContext(URL);
In case you want to get root site context then you can directly use get_root()
method.
如果您想获取根站点上下文,则可以直接使用get_root()
方法。
回答by DhruvJoshi
Try this
试试这个
var context = new SP.ClientContext(URL);