首页 > 解决方案 > 如何提供一个简单的静态 html 页面并使用提供的位置哈希

问题描述

我想提供一个页面并使用提供的位置哈希,以便页面向下滚动到正确的位置。由于 Google App Scripts 将输出放入包含的 iframe 中,因此顶部浏览器窗口中的哈希将被忽略。

我的 doGet() 看起来像这样:

function doGet(e) {  
  return HtmlService.createHtmlOutput(DriveApp.getFilesByName('My File.html').next().getBlob().getDataAsString());
}

这有效并且页面加载。这是一个完全静态的页面,在页面访问时不会生成任何内容。如果我缺少从 Google Drive 提供静态 html 文件的简单方法,请告诉我。现在我希望页面向下滚动到页面上的指定位置。网址看起来像

http://bit(dot)ly/myspecialwebpage#some-subject

这将重定向到类似的东西

https://script.google.com/macros/s/AK...Hckf/exec#some-subject

我尝试将此脚本放入 html 中,但它不起作用

<script>
  window.onload = function() {
    window.location.hash = window.top.location.hash
</script>

顶部窗口由 script.google.com 提供

并且 iframe 由 script.googleusercontent.com 提供

标签: htmlgoogle-apps-scriptweb-applications

解决方案


推荐阅读