You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

为Google Scripts Web App添加刷新按钮,实现上传后返回首页

Add a Refresh/Return Home Button to Your Google Drive Upload Script

Got it, let's get that user-friendly refresh button added to your upload tool—this will make it way simpler for your less tech-savvy users to get back to the home page without fumbling with browser refresh controls.

Here's how to implement it step by step:

  1. Open your script's HTML file (usually named index.html in your Google Apps Script project)
  2. Insert the button code in a visible spot, like right after your upload success message or at the bottom of the page:
    <button id="returnHomeBtn" style="padding: 10px 20px; background: #4285F4; color: white; border: none; border-radius: 4px; font-size: 14px; cursor: pointer;">返回首页</button>
    
  3. Add the click functionality by including this JavaScript snippet (you can put it at the end of your HTML file, just before the closing </body> tag):
    <script>
      document.getElementById('returnHomeBtn').addEventListener('click', function() {
        window.location.reload();
      });
    </script>
    

Bonus Tip:

If your script shows a success alert after upload, you can even trigger this button to appear only once the upload completes. For example, if you have a function that runs after a successful upload, add this line to show the button:

document.getElementById('returnHomeBtn').style.display = 'block';

(Just set the button's initial style to display: none; so it's hidden until needed.)

This solution is lightweight, intuitive, and exactly what your users need to avoid confusion with manual page refreshes.

内容的提问来源于stack exchange,提问作者Scott Ewing

火山引擎 最新活动