1,页面上有个_spPageContextInfo对象,可以获取一些我们需要的东西。
(1)获取当前用户Id
|
1 |
var userId=_spPageContextInfo.userId; |
(2)获取当前用户的登录名
|
1 |
var userLoginName=_spPageContextInfo.userLoginName; |
(3)获取网站的相对路径
|
1 |
var siteUrl=_spPageContextInfo.webServerRelativeUrl; |
通过该对象还可以获得好多东西,通过开发人员工具,在页面上找到该对象可以点出各种属性来。
2,除了上面的简单的获取当前用户Id,用户名的方式外,还有一种方法。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 |
function CallClientOM() { var
context = new
SP.ClientContext.get_current(); this.website = context.get_web(); this.currentUser = website.get_currentUser(); context.load(currentUser); context.executeQueryAsync( Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed) );} function onQuerySucceeded(sender, args) { alert(currentUser.get_loginName()); } function onQueryFailed(sender, args) { alert(‘request failed ‘
+ args.get_message() + ‘\n‘+ args.get_stackTrace()); } |
原文:http://www.cnblogs.com/wanren/p/3547970.html