如何刷新页面,Google应用脚本Web

5

下午好。

我正在尝试通过Google应用脚本Web创建一个刷新页面的按钮,但是方法“window.location.reload();”不起作用,有人能帮忙吗?

Google应用脚本Web链接:https://script.google.com/d/1jyWe9jm0dIqHsY1uKJZ0pOJYzLuq9dip1cSsXhxBwv53cFakW2LHgM_n/edit?mid=ACjPJvGbLXQwvhjDh7fsdifcTFvgQby-gsIUWeCSmwUzTdnVvXw8LNckG8rXcsyhcYvAcWAN7pU4E05bQEJwZl_1189N-bwyvttAxpHxmbvzUvx_d9SDKh19x3VzY9XxClhXweVlmqdMOSs&uiv=2

<html>

<base target="_se">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://tablesorter.com/__jquery.tablesorter.min.js" type="text/javascript"></script>

<button onclick="sortTable()">Sort</button>
<button onclick="refresh()">refresh </button>

  <table class="striped centered ajuste" id="tab">
           <thead >           
             <tr>

              <th>ID</th>
              <th>NOME</th>
              <th>DATA</th>

             </tr>
           </thead>
            <tbody id="coportoTabela">

            </tbody>
  </table>

 document.addEventListener("DOMContentLoaded", function(){

        google.script.run.withSuccessHandler(gerarTabela).pegarTabelaEstoque();

  });

  function gerarTabela(dataArray){
    var tcorpo =  document.getElementById("coportoTabela");    

     dataArray.forEach(function(r){

     var linha = document.createElement("tr");

     var coluna1 = document.createElement("td");
     coluna1.textContent = r[0];
     var coluna2 = document.createElement("td");
     coluna2.textContent = r[1];
     var coluna3 = document.createElement("td");
     coluna3.textContent = r[2];

     linha.appendChild(coluna1);
     linha.appendChild(coluna2);
     linha.appendChild(coluna3);

     tcorpo.appendChild(linha); 

     });      

  }


   function refresh(){
     window.location.reload();
   }     


这个回答解决了你的问题吗?如何使用链接重新加载Google Apps Script Web应用程序? - Rubén
这个回答解决了你的问题吗?无法阻止Google Apps Script掩盖重定向的URL - TheMaster
2个回答

17

试试这个:

Javascript:

function reLoad() {
       google.script.run
      .withSuccessHandler(function(url){
        window.open(url,'_top');
      })
      .getScriptURL();
}

GS:

function getScriptURL() {
  return ScriptApp.getService().getUrl();
}

2
终于!有适用于Apps Script应用的东西了。谢谢!Google对URL进行了一些奇怪的处理。 - jeff
对于文档,它适用于已部署的 Web 应用程序(链接末尾带有 exec),而不是开发模式。但是很好的解决方案!谢谢 :) - Waxim Corp
2023年8月更新。这个Cooper解决方案在开发模式下也非常完美。 - Nerea

1

在调用location.reload()之后,你应该在onclick函数中返回false:

function teste(){
location.reload();
return false;
}

函数能够正常工作,但屏幕全是白色的。 - Fragosojp
什么是白屏?它不是重新加载页面吗?你能在浏览器的网络选项卡中看到重新加载的页面吗? - Abilogos
请通过此应用程序链接查看:https://script.google.com/macros/s/AKfycbx3RHYokreumTcdvQ12PXnGoNSiXoOYKTLCPq6Tj6s/dev - Fragosojp
该页面在 script.google 的 iframe 中显示。我认为这可以防止内部脚本因恶意脚本而重新加载和重定向。这应该在您的本地计算机上正常工作。 - Abilogos

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接