javascript - 自动调整 Google 网站嵌入代码 (html) 的高度
问题描述
我正在使用 Google 协作平台嵌入 HTML 代码,将代码粘贴到“从网络嵌入”窗口中。输出的长度是可变的。
iframe
我希望有一种方法可以动态调整Google 协作平台用来托管我的 HTML的父级的高度。
我知道我可以使用 Google 协作平台用户界面手动分配更多空间,不幸的是内容会根据 API 的数据而有所不同,因此我无法事先知道高度。目前,只要内容超出分配的空间并且看起来不太好,就会出现垂直滚动条。
我尝试了以下操作,它只删除了滚动条,而不允许我查看内容:
<script>parent.document.getElementsByTagName('iframe')[0].scrolling="no";</script>
Google 网站示例位于https://sites.google.com/view/auto-ajust-gsite-embed/home
这是我在上面的示例站点中使用的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Bootstrap CSS -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl"
crossorigin="anonymous"
/>
<title>auto adjust google site embed</title>
</head>
<body>
<div class="accordion accordion-flush" id="accordionFlushExample">
<div class="accordion-item">
<h2 class="accordion-header" id="flush-headingOne">
<button
class="accordion-button collapsed"
type="button"
data-bs-toggle="collapse"
data-bs-target="#flush-collapseOne"
aria-expanded="false"
aria-controls="flush-collapseOne"
>
Accordion Item #1
</button>
</h2>
<div
id="flush-collapseOne"
class="accordion-collapse collapse"
aria-labelledby="flush-headingOne"
data-bs-parent="#accordionFlushExample"
>
<div class="accordion-body">
Placeholder content for this accordion, which is intended to
demonstrate the <code>.accordion-flush</code> class. This is the
first item's accordion body.
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="flush-headingTwo">
<button
class="accordion-button collapsed"
type="button"
data-bs-toggle="collapse"
data-bs-target="#flush-collapseTwo"
aria-expanded="false"
aria-controls="flush-collapseTwo"
>
Accordion Item #2
</button>
</h2>
<div
id="flush-collapseTwo"
class="accordion-collapse collapse"
aria-labelledby="flush-headingTwo"
data-bs-parent="#accordionFlushExample"
>
<div class="accordion-body">
Placeholder content for this accordion, which is intended to
demonstrate the <code>.accordion-flush</code> class. This is the
second item's accordion body. Let's imagine this being filled with
some actual content.
</div>
</div>
</div>
</div>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0"
crossorigin="anonymous"
></script>
</body>
</html>
解决方案
推荐阅读
- data-structures - 我可以在 Octave 中更改数据结构中的字段名称吗?
- css - 使用 CSS 在 HTML 上创建线指南
- windows - 用于激活 MS Office 的 Powershell 脚本
- python - 如何处理具有多种数据类型的熊猫数据框中的列?
- c++ - 如何删除动态分配的二维数组?
- javascript - 返回数组类型的不同方式(通过graphql返回的数据)
- java - 为什么我的 try-catch 在我的代码中不起作用?
- visual-studio-code - 当我保存js文件时,vscode在构造函数中插入括号
- docker - 如何在 docker run 中实现环境变量替换并在剩余的环境变量中相对使用一个变量
- javascript - 处理 React Redux 表单中的提交异常