Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

How to display the current username and time zone in sharepoint as a label or placeholder instead of an alert box?

$
0
0

Hi,

I want to display the current username and time zone in my SharePoint page as a placeholder instead of an alert box. I have the script which I used for displaying the alert box. Please help me out.


<script type="text/javascript">
  var userid= _spPageContextInfo.userId;
  var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";
  var requestHeaders = { "accept" : "application/json;odata=verbose" };
  $.ajax({
    url : requestUri,
    contentType : "application/json;odata=verbose",
    headers : requestHeaders,
    success : onSuccess,
    error : onError
  });

  function onSuccess(data, request){
    var loginName = data.d.Title;
    alert(loginName);
  }

  function onError(error) {            
    alert("error");
  }

var t = new Date();
var utc_offset = t.getTimezoneOffset();
t.setMinutes( t.getMinutes() + utc_offset);
console.log("UTC : " +t);
var timeZone = t;
alert(timeZone)</script>


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>