Google Apps脚本无法在嵌入式iframe中使用 [英] Google Apps script not working in an embedded iframe
本文介绍了Google Apps脚本无法在嵌入式iframe中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Google表格,在其中放置了一些链接到脚本的按钮.当我在工作表页面上使用它时,它工作正常.但是,当我发布并将其嵌入到我的网站上时,该按钮不起作用.它没有执行.下面是我通过单击按钮和使用的iframe代码从一张纸移动到另一张纸的示例代码.
I have a Google sheet where I have placed a few buttons linking to the script. It works fine when I use it on the sheets page. But when I publish it and embed the sheet on my website, the button doesn't work. It's not performing. Below is the sample code I use to move from one sheet to another with the click of the button and the iframe code I am using.
function goToInward() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName("Inward"));
}
<iframe src="https://docs.google.com/spreadsheets/d/e/xxxxxxxxxxxxxxxxx/pubhtml?widget=true&headers=false" frameborder="0" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;height:100%;width:100%;position:absolute;top:55px;left:0px;right:0px;bottom:0px" height="100%" width="100%"></iframe>
推荐答案
当您将Google电子表格发布到网络上时-这是仅查看访问权限
- 实际上,如果您在浏览器地址栏中键入直接发布链接:
https://docs.google.com/spreadsheets/d/e/xxxxxxxxxxxxxxxxx/pubhtml?widget=true&headers=false
,您将看到您同样仅获得电子表格的查看版本 - 您无法在电子表格中执行编辑,因此您无法运行Apps脚本-因为后者需要编辑权限
- Indeed, if you type into your browser address bar the direct publish link:
https://docs.google.com/spreadsheets/d/e/xxxxxxxxxxxxxxxxx/pubhtml?widget=true&headers=false
, you will see that you likewise obtain only a view version of the spreadsheet - You cannot perform edits in the spreadsheets, and consequently you cannot run an Apps Script - since the latter requires edit access
- 发布电子表格时,您可以在URL中指定应显示的工作表
- 默认情况下,它是第一张纸,但是如果您不确定,例如
https://docs.google.com/spreadsheets/d/e/xxxxxxxxxxxxxxxxx/pubhtml?widget=true&headers=false#gid=yyyyyyyyy
,然后将打开工作表ID为yyyyyyyyy
的工作表 - 因此,您可以在网站中创建自己的工作表更改脚本
- 为此,只需创建一个html按钮并指定在单击按钮时应将用户重定向到工作表
- When publishing a spreadsheet, you can specify in the URL which sheet shall be shown
- By default, it is the first sheet, but if you specofy e.g.
https://docs.google.com/spreadsheets/d/e/xxxxxxxxxxxxxxxxx/pubhtml?widget=true&headers=false#gid=yyyyyyyyy
, then the sheet with the sheet idyyyyyyyyy
will be opened - Consequently, you can create your own sheet changing script within your Website
- For this, simply create an html button and specify that on button click the user shall be redirected to the sheet
When you publish a a Google spreadsheet to the Web - it is view only access
WORKAROUND
样品
<iframe id="frame" src="https://docs.google.com/spreadsheets/d/e/xxxxxxxxxxxxxxxxx/pubhtml?widget=true&headers=false" frameborder="0" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;height:100%;width:100%;position:absolute;top:55px;left:0px;right:0px;bottom:0px" height="100%" width="100%"></iframe>
<button onclick="myFunction()">Change tabs</button>
<script>
function myFunction(){
document.getElementById("frame").src = "https://docs.google.com/spreadsheets/d/e/xxxxxxxxxxxxxxxxx/pubhtml?widget=true&headers=false#gid=yyyyyyyyy";
}
</script>
这篇关于Google Apps脚本无法在嵌入式iframe中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文