Google Slide modalDialog HTML javascript能否运行服务器端代码?环境应用程序脚本
不要列出幻灯片。代码中的警报显示javascript正在运行,但不显示服务器端代码Google Slide modalDialog HTML javascript能否运行服务器端代码?环境应用程序脚本,javascript,html,google-apps-script,google-slides,Javascript,Html,Google Apps Script,Google Slides,不要列出幻灯片。代码中的警报显示javascript正在运行,但不显示服务器端代码 <!DOCTYPE html> <html> <head> <base target="_top"> <style> 在我的一个警报中发现缺少报价,现在服务器端脚本已成功运行。谢谢大家。很抱歉这么笨 它仍然会得到身份验证错误: Exception: You do not have permission to c
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<style>
在我的一个警报中发现缺少报价,现在服务器端脚本已成功运行。谢谢大家。很抱歉这么笨 它仍然会得到身份验证错误:
Exception: You do not have permission to call SpreadsheetApp.openById. Required permissions: https://www.googleapis.com/auth/spreadsheets
从驱动器打开或刷新时,即使项目在清单中。尽管有这个错误,它仍然有效
{
"timeZone": "America/Mexico_City",
"dependencies": {
"enabledAdvancedServices": [{
"userSymbol": "Slides",
"serviceId": "slides",
"version": "v1"
}, {
"userSymbol": "Drive",
"serviceId": "drive",
"version": "v2"
}]
},
"exceptionLogging": "STACKDRIVER",
"oauthScopes": [
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/presentations",
"https://www.googleapis.com/auth/script.container.ui"],
"runtimeVersion": "V8"
}
调用服务器函数flipDice的最终工作HTML
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<style>
CSS removed for simplicity
</style>
</head>
<body>
<div id="parent">
<div id="child">
<?!= nextQuestion ?>
<p></p>
<input type="button" value="Okay!" id="subBut" />
<input type="button" value="Not quite" onclick="google.script.host.close()" />
</div>
</div>
<script>
// - - - - - - - - LISTENERS - - - - - - - -
document.getElementById("subBut").addEventListener("click",
function(event) {
// alert("Begin submit addEventListener");
goodJob();
// event.preventDefault(); //stop form from submitting
} );
// - - - - - - - - FUNCTIONS - - - - - - - -
function goodJob() {
// alert("In goodJob ");
// google.script.host.close();
// alert('Call flipDice' );
try {
google.script.run
.withSuccessHandler( succeed )
.withFailureHandler( fail )
.flipDice();
} catch (e) {
alert(" google.script.run flipDice caught error: " + e);
}
// alert("end goodJob ");
}
function succeed () {
google.script.host.close();
alert('Success from serverside flipDice');
}
function fail (err) {
alert('Handler fail - err: ' + err
+ ' received from serverside flipDice');
}
</script>
</body>
</html>
为了简单起见,删除了CSS
//听众-
document.getElementById(“subBut”).addEventListener(“单击“,
功能(事件){
//警报(“开始提交addEventListener”);
goodJob();
//event.preventDefault();//停止表单提交
} );
//功能
函数goodJob(){
//警惕(“在好工作中”);
//google.script.host.close();
//警报(“呼叫flipDice”);
试一试{
google.script.run
.withSuccessHandler(成功)
.withFailureHandler(失败)
.flipDice();
}捕获(e){
警报(“google.script.run flipDice捕获错误:+e);
}
//警报(“结束goodJob”);
}
函数成功(){
google.script.host.close();
警报(“服务器端flipDice成功”);
}
功能失败(err){
警报('处理程序失败-错误:'+错误
+“从服务器端flipDice接收”);
}
我认为使用尝试将google.script.host.close()
放入with successhandler()
@Cooper中似乎没有任何区别。成功关闭对话框意味着它没有被执行。对于新读者,我还有一个关于幻灯片的开放问题。最近的测试在CreateMenue中捕获了try/catch错误:{[Exception:无法从此上下文调用SlidesApp.getUi()]name:'Exception'}在onOpen createMenu中,但当onOpen在编辑器中运行时,会显示该菜单,尽管我不确定这是否是您的错误复制,我认为您的这个标签
没有子ID,而是。这样,当按下按钮时,就可以了单击“代码>”,则不执行任何操作。这个怎么样?顺便问一下,我能问一下你的这个问题和你之前评论中的问题之间的关系吗?你能澄清一下遗漏的引语在哪里吗?@lamblichus抱歉。我通过删除此警报中的结束引号重新创建了问题。警报(“开始提交addEventListener);编辑器不会更改代码的外观。我不确定这是确切的警报,但这是警报中的最后一个引号。flipDice
在启用V8时是否成功返回?我必须为此禁用V8。@在找到缺少的引号后,打开或关闭V8的lamblichus似乎没有任何区别。服务器ide代码从html运行。它总是在从幻灯片自定义菜单调用时运行。
{
"timeZone": "America/Mexico_City",
"dependencies": {
"enabledAdvancedServices": [{
"userSymbol": "Slides",
"serviceId": "slides",
"version": "v1"
}, {
"userSymbol": "Drive",
"serviceId": "drive",
"version": "v2"
}]
},
"exceptionLogging": "STACKDRIVER",
"oauthScopes": [
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/presentations",
"https://www.googleapis.com/auth/script.container.ui"],
"runtimeVersion": "V8"
}
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<style>
CSS removed for simplicity
</style>
</head>
<body>
<div id="parent">
<div id="child">
<?!= nextQuestion ?>
<p></p>
<input type="button" value="Okay!" id="subBut" />
<input type="button" value="Not quite" onclick="google.script.host.close()" />
</div>
</div>
<script>
// - - - - - - - - LISTENERS - - - - - - - -
document.getElementById("subBut").addEventListener("click",
function(event) {
// alert("Begin submit addEventListener");
goodJob();
// event.preventDefault(); //stop form from submitting
} );
// - - - - - - - - FUNCTIONS - - - - - - - -
function goodJob() {
// alert("In goodJob ");
// google.script.host.close();
// alert('Call flipDice' );
try {
google.script.run
.withSuccessHandler( succeed )
.withFailureHandler( fail )
.flipDice();
} catch (e) {
alert(" google.script.run flipDice caught error: " + e);
}
// alert("end goodJob ");
}
function succeed () {
google.script.host.close();
alert('Success from serverside flipDice');
}
function fail (err) {
alert('Handler fail - err: ' + err
+ ' received from serverside flipDice');
}
</script>
</body>
</html>