Javascript for personal Sharepoint

In my organization, there is no direct link to our personal Sharepoint site. Only the team site is directly available from the office sidebar. Unfortunately, two different domain are used to host students and teacher depending on their email.

Here is a little script that I included in Moodle to let my student and other teachers access there microsoft sharepoint site.

Remarks:

  1. No form tag : The form tag make the page change when the user click submit. I wanted the page NOT to change.
  2. Double = : In the if, you have to use the “==”
  3. Not found : the string search returns -1 when nothing is found
<input id="myEmail" name="email" value="" type="text" /> <input style="background: blue; color: white;" value="sharepoint" onclick="
var myEmail = document.getElementById('myEmail');
var str = myEmail.value; var myLink = document.getElementById('myLink'); 
str = str.replace('.','_');
str = str.replace('@','_');
var domain = 'domain1';
if (str.search('domain1_com') == -1) { domain = 'domain2'};
var myUrl = 'https://'+domain+'-my.sharepoint.com/personal/'+str+'/_layouts/15/viewlsts.aspx?view=14';
if (str =='') {alert('saissisez votre mail / type your email')} else {window.open(myUrl, '_blank')}" type="submit" />

Partagez: