How to refresh web page, after sheet has been updated (New Google Sites)

3,842 views
Skip to first unread message

Alistair George

unread,
Apr 22, 2020, 6:16:54 PM4/22/20
to Google Apps Script Community

Hi.
My web page has a HTML search box, and a Google Sheet. The user inputs their search into the HTML box:

//Apps script:
function doGet(e) {
 
return HtmlService.createHtmlOutputFromFile('searchbox').setSandboxMode(HtmlService.SandboxMode.IFRAME);  
}



//html/searchbox
<!DOCTYPE html>
<html>
<form>
<input type="search" id="q" name="submit" placeholder="Search for song name..." required>
<button onclick="bclick(q.value)">Search</button />
</form>

<script type="text/
javascript">
function bclick(q) {
google.script.run.afterhtml(q);
}
</script>
</html>

I have 3 problems;
1..when the searchbox button is pressed, the searchbox script ends, and the box dissappears - it would preferably stay.
2..Once the search has completed, the sheet is updated, but unless the user manually updates the page, they cant see the results (the sheet is dynamically created, so is not attached to the script)
3..In order to refresh the page, it seems I need to run another HtmlService but I havent been able to do this outside of the doget() function.

As usual, Ive asked my friend Google, but havent been able to find anything that seems to work. There were suggestions of
window.location.reload(true);
Appreciate,
Al.

Alan Wells

unread,
Apr 22, 2020, 7:43:15 PM4/22/20
to Google Apps Script Community
The reason that your form disappears is because that is the way it is designed to work.  That is what <form> tags do.  There are multiple ways to deal with this problem, and people have their preferences.  If you want to use a <form> tag, then you need to move any button outside if the form tags, or use something called prevent default.

If you want to update the html, there are basically two ways to do that, refresh the page with the Web App, or use a withSuccessHander(fnkToUpdateTheHTML) and use the DOM to change the HTML.

reload
Reply all
Reply to author
Forward
0 new messages