我想知道是否有可能与谷歌应用程序脚本来显示一个HTML文件的内容 返回HtmlService.createHtmlOutputFromFile('0'); ,在文件内部有一个按钮,当按下按钮时,它将导致屏幕删除当前信息并用第二个html文件替换它本身 return HtmlService.createHtmlOutputFromFile('1'); 。 *注意我不想链接到谷歌文档或其他网页。只是想知道你是否可以在同一个脚本文件内的html文件之间切换。如果可能的话,我的推理是有一个“菜单”页面,它将显示不同的主题,并在一个文档中保持更好的组织。Google Apps脚本切换html文件
0
A
回答
0
这是可能的程度。我们将暗示有一种功能可以从HTML文件中获取信息,然后将其写入页面中。如果你希望能够浏览,那么每个.html
文件你必须具有以下功能的<script></script>
function changePage(page) {
document.open(); //should work fine without this
document.write(page);
document.close(); //should work fine without this
}
该位将处理不断变化的整个页面与新内容的内容。现在我们需要以某种方式获得该内容。这将与.gs
文件在你的谷歌脚本,看起来像这样
function newPage(page) {
return HtmlService.createHtmlOutputFromFile(page).getContent()
}
那么你的页面里面,只要你想换一个新的,你需要有内部的函数来完成比方说,一个按钮:
<button onclick="google.script.run.withSuccessHandler(changePage).newPage('success')">Next Page</button>
在这种情况下,newPage()
函数需要一个字符串,它会说明什么是html的名称。因此,逻辑下面我们将做
return HtmlService.createHtmlOutputFromFile('success').getContent()`
一旦我们按下该按钮,一旦脚本完成并返回我们想要的HTML的字符串,我们就用它来设置当前页面的HTML。
下面是它如何工作的完整示例。您可以导航Index.html
success.html
之间
Code.gs
function doGet() {
return HtmlService.createHtmlOutputFromFile('Index');
}
function newPage(page) {
return HtmlService.createHtmlOutputFromFile(page).getContent()
}
的Index.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<script>
function changePage(page) {
document.open();
document.write(page);
document.close();
}
</script>
<body>
First Page
<button onclick="google.script.run.withSuccessHandler(changePage).newPage('success')">Next Page</button>
</body>
</html>
success.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<script>
function changePage(page) {
document.open();
document.write(page);
document.close();
}
</script>
<body>
It worked!
<button onclick="google.script.run.withSuccessHandler(changePage).newPage('Index')">First Page</button>
</body>
</html>
相关问题
- 1. 在Google Apps脚本HTML服务中切换帐户
- 2. Google Apps脚本:UrlFetchApp发布文件
- 3. 多个文件上传Google Apps脚本
- 4. Google Apps脚本上传大文件
- 5. Google Apps引擎,Google Apps脚本和Javascript
- 6. 从Google Apps脚本
- 7. Google Apps脚本DockPanel
- 8. Google Apps脚本[createServerClickHandler]
- 9. 将Google Apps脚本实施为HTML
- 10. 如何从Google Apps脚本输出HTML?
- 11. Google Apps脚本WebApp将html传递到文件
- 12. Google Apps脚本日历说明 - 换行
- 13. Google Apps脚本Utilities.parseCsv()和替换字符 -
- 14. 将VBA转换为Javascript(Google Apps脚本)
- 15. 从Google Apps脚本运行python脚本
- 16. Google Apps脚本执行API
- 17. Google Apps脚本不良值
- 18. getRoot Google Apps脚本问题
- 19. VBA和Google Apps脚本
- 20. 使用Google Apps脚本
- 21. Google Apps脚本 - 集成XFrameOptions
- 22. Google Apps脚本挂起(javascript)
- 23. Parse Json - Google Apps脚本
- 24. Google Apps脚本替代ScriptProperties
- 25. Google Apps脚本getLastRow错误(
- 26. Google Apps脚本oAuth 2.0
- 27. 的iframe Google Apps脚本
- 28. Google Apps脚本查询MariaDB
- 29. Google Apps脚本MailApp使用htmlBody文档
- 30. 脚本Google Apps演示文稿
是的,这是可能的。 Apps脚本有一个名为HtmlService的服务。您可以使用HtmlService创建侧边栏,对话框和Web应用程序。删除和替换HTML的能力主要是使用所谓的DOM的结果。如果您创建边栏,对话框或Web应用程序,它将是JavaScript,DOM,CSS,Apps脚本代码和HTML的组合。所有这些东西都是独立的东西,但DOM经常被混淆为JavaScript,Apps Script可能会与JavaScript混淆。 Apps脚本使用JavaScript,但Apps脚本服务特定于Google产品。 –
要完成你想要的任务,你可以使用DOM属性innerHTML。 [链接到innerHTML信息](http://www.w3schools.com/jsref/prop_html_innerhtml.asp) –
对不起,我不想简单地修改HTML页面中的DOM。我想要做的是从一个初始html文件开始(返回HtmlService.createHtmlOutputFromFile('0');)并使用该文件中的按钮,让该页面擦除初始模型并将其替换为另一个(返回HtmlService.createHtmlOutputFromFile( '1'))。我知道并理解文档对象模型并使用javascript更改数据。我只是没有找到一种方法来替换GAS的初始“返回”值,而不是简单地链接到完全不同的GAS Web应用程序。 – ZeroWolfCode