Google脚本-边栏按钮不断打开新标签页 [英] Google Script - Sidebar button keeps opening a new tab

查看:48
本文介绍了Google脚本-边栏按钮不断打开新标签页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个非常基本的脚本,以协助我完成一个Google电子表格.

I'm creating an extremely basic script to assist me in one of my google spreadsheets.

我已经成功显示了一个带有一些按钮(功能)的侧边栏.但是,每当我单击其中一个按钮时,它也会打开一个新标签,其URL类似于:" https://n-lx3mdv5ls3mdgglsq226llilxd2m4owxy72y3fy-1lu-script.googleusercontent.com/userCodeAppPanel ?"

I've successfully got a sidebar showing, with a few buttons (which function). However, whenever I click on one of those buttons, it also opens up a new tab, with a URL something like: "https://n-lx3mdv5ls3mdgglsq226llilxd2m4owxy72y3fy-1lu-script.googleusercontent.com/userCodeAppPanel?"

即使按钮没有任何功能,这种情况仍然会发生.

Even if the button is left without any functionality, this still occurs.

这是html的示例:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
    <!-- The CSS package above applies Google styling to buttons and other elements. -->

    <style>
    
    </style>
  </head>
  <body>
    <div class="sidebar">
      <form>
       <div class="block" id="buttons">
          <button id="unindent">Unindent</button>
          <button id="indent">Indent</button>
          <button id="asdgdgasg">Test</button>
        </div>
      </form>
    </div>
  </body>
</html>

如何阻止每次打开新标签页?

How can I stop this new tab from opening every time?

推荐答案

问题:

  • <button>类型(如果未指定)默认为type=submit.因此,该表单会自动将数据提交到服务器.这在iframe中不是可取的.
  • Issue:

    • <button> type, if not specified defaults to type=submit. So, The form automatically submits the data to the server. This is not preferable in a iframe.
      • 将按钮类型明确指定为按钮. >
      • 使用event.preventDefault()阻止自动提交表单.
      • Explicitly specify button type as button. <button type='button'>
      • Use event.preventDefault() to prevent automatic form submission.
      • Button#Default
      • Sample Form

      这篇关于Google脚本-边栏按钮不断打开新标签页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆