Quantcast
Channel: TechNet Blogs
Viewing all articles
Browse latest Browse all 36188

Getting the current user’s alias

$
0
0

For a project I’m working on, I needed to know what the logged in user’s account alias was.  Looking around I found examples that would make a ajax call out to the profile page and parse the results.  This seemed like overkill for what I wanted and on a whim I decided to view-source on the Search Center results page and search for my user name… Sure enough, there it is:

accountname

The hidden QLogEnv inputs are used to click event tracking but this is good enough for me.   Here’s the JQuery I used to pull it out:

function pullAlias() {
  // Pull the alias or return null
  var p = /<un>[a-zA-Z]+\\([^<]+)/;
  var l = $('input').map(function(index) {
  if (this.name.startsWith("QLogEnv") && (this.value.indexOf("<un>") != -1)) {
   var r = p.exec(this.value);
   if (r) {
    return r[1]
   }
  }
  })
  if (!l) { return } // no alias found?
  return l[0]
}


Viewing all articles
Browse latest Browse all 36188

Trending Articles