Remarks:
- No form tag : The form tag make the page change when the user click submit. I wanted the page NOT to change.
- Double = : In the if, you have to use the "=="
- 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" />