I create function get gmail when user use my app in file gs. When i call function via file script html it run but don't get gmail ?
I try test open new web browsers, log in with account gmail and pass URL of apps script but not show my gmail.
Code in file .gs:
function checkAccSS(){
var email = Session.getActiveUser().getEmail();
Logger.log(email); // I test it show my gmail
return email;
}
Code in file .html:
<!DOCTYPE html>
<html>
<head>
</head>
<body onload="doLoadGmail()">
<p id="demo"></p>
<script>
function doLoadGmail(){
google.script.run.withSuccessHandler(checkGmall).checkAccSS();
}
function checkGmall(email){
document.getElementById("demo").innerHTML = "Gmail " + email;// not show gmail in html !
console.log(info); // not show gmail here !
}
</script>
</body>
</html>
As far as I can see this happens because your script 'doLoadGmail()' that executes the script 'checkAccSS' is only called on load. You could add a button with an onclick event that would execute your script without reloading however this wouldn't do it automaticly.
If you would like to this automaticly you could check the documentation from Ajax https://www.w3schools.com/jquery/jquery_ref_ajax.asp