为Google Scripts Web App添加刷新按钮,实现上传后返回首页
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:
- Open your script's HTML file (usually named
index.htmlin your Google Apps Script project) - 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> - 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




