【发布时间】:2023-02-01 10:13:43
【问题描述】:
我最近尝试使用 Google 协作平台在我的网站上实现自定义按钮,只是为了执行一个基本功能:滚动到某个部分或顶部。没想到会这么难...
我必须使用嵌入代码来添加我的按钮(否则无法自定义它们)但这会使它们显示在 iframe 中。
onclick 和 window.top 似乎根本不起作用(或者我做错了)。
我的临时解决方案如下,但它会在滚动前打开一个新选项卡,所以效果不是很好:
.button-test {
background-color: #0078d0;
border: 0;
border-radius: 56px;
color: #fff;
cursor: pointer;
display: inline-block;
font-family: system-ui, -apple-system, system-ui, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", sans-serif;
font-size: 18px;
font-weight: 600;
outline: 0;
padding: 16px 21px;
position: relative;
text-align: center;
text-decoration: none;
transition: all .3s;
user-select: none;
-webkit-user-select: none;
touch-action: manipulation;
}
.button-test:before {
background-color: initial;
background-image: linear-gradient(#fff 0, rgba(255, 255, 255, 0) 100%);
border-radius: 125px;
content: "";
height: 50%;
left: 4%;
opacity: .5;
position: absolute;
top: 0;
transition: all .3s;
width: 92%;
}
.button-test:hover {
box-shadow: rgba(255, 255, 255, .2) 0 3px 15px inset, rgba(0, 0, 0, .1) 0 3px 5px, rgba(0, 0, 0, .1) 0 10px 13px;
transform: scale(1.05);
}
@media (min-width: 768px) {
.button-test {
padding: 16px 48px;
}
}
<a href="http://test.com/en#h.2f00a9eddc84963_56">
<button class="button-test" role="button">Test Button</button>
</a>
无法找到使主/顶部窗口刷新而不打开新选项卡以滚动到该部分的函数或脚本。 有没有人找到解决方案? 我真的希望如此……我不明白为什么 Google 协作平台如此有限。
这是一个例子:sites.google.com/view/testcustombutton
据我了解,这与自动生成的沙箱 iframe 没有允许顶部导航选项有关。 有没有办法改变或绕过它?
【问题讨论】:
-
您想要超链接 (
<a>) 标签内的按钮有什么特别的原因吗?为什么不简单地将超链接标记样式设置为看起来像一个按钮呢? -
嗨 blurfus,没有特别的原因。我从一个按钮开始,但无法使 onclick 在其 iframe 之外工作,因此转移到超链接标签解决方案。但无论哪种方式,它仍然会在 Google 协作平台中打开一个新标签
-
没有足够的信息可以提供帮助。默认情况下,超链接(或按钮)不会在新选项卡中打开。请在您的问题中包含 minimal reproducible example,以便更快地进行故障排除。另请阅读我们的How to Ask 页面以获取有关如何改进此问题的更多提示
-
我在这里发布了一个示例:sites.google.com/view/testcustombutton 我无法提供确切的代码,因为它是由 Google 协作平台自动生成的
-
无法解决这个问题——这是一个位于多个其他 iframe 内的 iframe 内的 iframe……首先想到的是:为什么有这么多 iframe?
标签: javascript jquery button embed google-sites-2016