Google Script - Sidebar button keeps opening a new tab

前端 未结 2 1335
野性不改
野性不改 2020-12-12 04:02

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

I\'ve successfully got a sidebar showing, with a few buttons (which function).

相关标签:
2条回答
  • 2020-12-12 04:08

    When I saw your issue, I thought that this is due to <form>. So I proposed the following modifications.

    1. Modify <form> to <form onsubmit="event.preventDefault()">.

    2. Modify <base target="_top"> to <base target="_self">.

    3. Remove <base target="_top">.

    Note:

    • I think that @TheMaster's answer is more useful information.

    References:

    • Event.preventDefault()
    • The Document Base URL element
    0 讨论(0)
  • 2020-12-12 04:22

    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.

    Solution:

    • Explicitly specify button type as button. <button type='button'>
    • Use event.preventDefault() to prevent automatic form submission.

    References:

    • Button#Default
    • Sample Form
    0 讨论(0)
提交回复
热议问题