【问题标题】:How to refresh page, Google app Script Web如何刷新页面,Google app Script Web
【发布时间】:2020-07-16 00:47:21
【问题描述】:

下午好。

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

链接 Google 应用脚本网站: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();
   }     

【问题讨论】:

标签: javascript html google-apps-script web-applications


【解决方案1】:

试试这个:

Javascript:

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

GS:

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

【讨论】:

  • 终于!适用于 Apps 脚本应用程序的东西。谢谢!谷歌对 URL 做了一些奇怪的处理。
  • 对于文档,它适用于已部署的 webapp(最后带有 exec 的链接),而不是在开发模式下。但是很好的解决方案!谢谢:)
【解决方案2】:

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

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

【讨论】:

  • 该功能甚至可以工作,但屏幕全白
  • 白屏是什么意思?是否重新加载页面?你能在浏览器网络标签中看到重新加载的页面吗?
  • 看穿这个应用链接:script.google.com/macros/s/…
  • 页面从 script.google 中的 iframe 显示。我认为它可以防止内部脚本由于恶意脚本而重新加载和重定向。这应该可以在您的本地电脑上正常工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-24
  • 1970-01-01
  • 1970-01-01
  • 2019-03-29
  • 1970-01-01
  • 2016-08-10
相关资源
最近更新 更多