在userCodeAppPanel

时间:2018-08-09 01:12:32

标签: javascript google-apps-script google-chrome-devtools

这是Google Spreadsheet中包含的脚本中的代码。唯一的其他代码是一个onOpen,它创建并菜单,还有一个showDialog()函数

function showDialog(){
  userInterface=HtmlService.createHtmlOutputFromFile('test');
  SpreadsheetApp.getUi().showModelessDialog(userInterface, 'Testing Inputs');
}

这是我的javascript

<script>
    var idA=['pdCliT','pdLocT','pdTypS','pdNamT','pdSupT','pdOutS','pdGasT','pdFloS','pdAmiS','pdUopN','pdVolN','pdDru','pdLOMN'];
    $(function(){});
    function testInputs(){
      console.log('idA.join(\',\')= %s',idA.join(', '));
      for(var i=0;i<idA.length;i++){
        var id='#' + idA[i];
        var type=String(idA[i]).slice(-1);
        console.log('idA[%d]=%s , id= %s',i,idA[i],id);  
        switch(type){
          case 'N':
            var min=$(id).attr(min);
            var max=$(id).attr(max);
            var val=$(id).val();
            console.log('type: number, min: %s, max: %s, val: %s',min,max,val);
            break;
          case 'T':  
            var val=$(id).val();
            console.log('type: text, value: %s',val);
            break;
          case 'S':
            console.log('value: %s',$(id).val());
            break;
          default:
            var val=$(id).val();
            console.log('value: %s', val);
        }
      }  
    }
    console.log('test code');
    </script>

这就是我在控制台中单击与“测试代码”关联的链接时看到的内容。

<!doctype html>
<style nonce="zBEN3oEdQQRu7CJxQEbQJdjrskg">
    html, body, iframe {
        border: 0;
        display: block;
        height: 100%;
        margin: 0;
        padding: 0;
        width: 100%;
    }

    iframe#userHtmlFrame {
        overflow-y: scroll;
        -webkit-overflow-scrolling: touch;
    }
</style>
<meta name="chromevox" content-script="no">
<script type="text/javascript" src="/static/macros/client/js/769718587-mae_html_user_bin_i18n_mae_html_user.js" nonce="zBEN3oEdQQRu7CJxQEbQJdjrskg"></script>
<script nonce="zBEN3oEdQQRu7CJxQEbQJdjrskg">
    maeInit_(true);
</script>
<iframe id="userHtmlFrame" allow="accelerometer *; ambient-light-sensor *; autoplay *; camera *; encrypted-media *; fullscreen *; geolocation *; gyroscope *; magnetometer *; microphone *; midi *; payment *; picture-in-picture *; speaker *; usb *; vibrate *; vr *" src="/blank"></iframe>
<form id="example_form"></form>

这是整个html文件。

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script>
    var idA=['pdCliT','pdLocT','pdTypS','pdNamT','pdSupT','pdOutS','pdGasT','pdFloS','pdAmiS','pdUopN','pdVolN','pdDru','pdLOMN'];
    $(function(){});
    function testInputs(){
      console.log('idA.join(\',\')= %s',idA.join(', '));
      for(var i=0;i<idA.length;i++){
        var id='#' + idA[i];
        var type=String(idA[i]).slice(-1);
        console.log('idA[%d]=%s , id= %s',i,idA[i],id);  
        switch(type){
          case 'N':
            var min=$(id).attr(min);
            var max=$(id).attr(max);
            var val=$(id).val();
            console.log('type: number, min: %s, max: %s, val: %s',min,max,val);
            break;
          case 'T':  
            var val=$(id).val();
            console.log('type: text, value: %s',val);
            break;
          case 'S':
            console.log('value: %s',$(id).val());
            break;
          default:
            var val=$(id).val();
            console.log('value: %s', val);
        }
      }  
    }
    console.log('test code');
    </script>
    <style>
    div#menu input[type=button]{margin:0 5px 5px 0;}
    div#content input, select{margin: 5px 2px;}
    #content{width:400px;}
    </style>
  </head>
  <body>
  <div id="menu"></div>
  <div id="content">
    <h1 id="hdg1">Basic Project Data Input</h1>
    <input type="text" id="pdCliT" value="Client Name" placeholder="Client" size="20" /><label for="pdCliT">Client</label><br />
    <input type="text" id="pdLocT" value="Client Location" placeholder="Unit Type" size="20" /><label for="pdLocT">Location</label><br />
    <select id="pdTypS" class="control"><option value="Select Unit Type" selected>Select Unit Type</option></select><label for="pdTypS">Unit Type</label><br />
    <input type="text" id="pdNamT" value="Value 1" placeholder="Unit Name" size="20" /><label for="pdNamT">Unit Name</label><br />
    <input type="text" id="pdSupT" value="Value 2" placeholder="Catalyst Supplier" size="20" /><label for="pdSupT">Catalyst Supplier</label><br />
    <select id="pdOutS" class="control"><option value="Select Catalyst Outcome" selected>Select Catalyst Outcome</option></select><label for="pdOutS">Catalyst Outcome</label><br />
    <input type="text" id="pdGasT" value="Value 3" placeholder="Carrier Gas" size="20" /><label for="pdGasT">Carrier Gas</label><br />
    <select id="pdFloS" class="control"><option value="Select Gas Flow" selected>Select Gas Flow</option></select><label for="pdFloS">Gas Flow</label><br />
    <select id="pdAmiS" class="control"><option value="Select Amine Scrubbing" selected>Select Amine Scrubbing</option></select><label for="pdAmiS">Amine Scrubbing</label><br />
    <input type="number" id="pdUopN" value="5000" placeholder="Operating Pressure psig" size="20" min="0" max="10000" step="100" title="Not greater than 10000" /><label for="pdUopN">Unit Operating Pressure, psig</label><br />
    <input type="number" id="pdVolN"  value="1000" placeholder="Reactor Value ft3" size="20" min="0" max="200000" step="1000" title="Not greater than 200000" /><label for="pdVolN">Reactor Volume,ft3</label><br />
    <input type="number" id="pdDruN" value="200" placeholder="Drum of QTRX2" size="20" min="0" max="500" step="100" title="Not greater than 500"/><label for="pdDruN">Drums of QTRX2</label><br />
    <input type="text" id="pdLOMT" value="Value 4" placeholder="Lead OM" size="20" /><label for="pdLOMT">Lead OM</label><br />
    <input type="button" id="tstInputs" value="Test Inputs" onClick="testInputs();" />
  </div>
  </body>
</html>

这是我启动对话框时控制台显示的内容

Unrecognized feature: 'picture-in-picture'.
iframedAppPanel?mid=ACjPJvGGulDc8kqHqaTVmW8ouofBnAMf3yo988NOBs-h9XUGoRpmfzwLx1oicxsS_tKSejiCuGZgzG7Uk-hD97zxYEj_J7Qna3k88V4wF0VJZqY0qcngq85y83fmy-indV7uqhh-nwbcfmY:11 Unrecognized feature: 'vibrate'.
userCodeAppPanel:2 Unrecognized feature: 'picture-in-picture'.
userCodeAppPanel:2 Unrecognized feature: 'vibrate'.
userCodeAppPanel:30 test code
2877393808-warden_bin_i18n_warden.js:202 To {message: "There was an error during the transport or process…this request. Error code = 10, Path = /wardeninit", name: "TransportError", stack: "TransportError: There was an error during the tran…/js/2877393808-warden_bin_i18n_warden.js:186:252)"}

这是我从另一个项目中提取的简单文件。我正在无模式对话框中运行它,但是在Web应用程序中却遇到了同样的问题,该问题已经通过控制台进行了调试。

如果您有任何想法,我将不胜感激。我尝试进行设置,然后单击“还原默认值并重新加载”。最近我一直在使用控制台进行调试,因为我似乎无法弄清楚。

我想知道它是否与图片中的图片和振动警告有关。我用不同的方式搜索了他们,但找不到任何帮助。

  

为回答您的问题,“您可以在使用本机Javascript而不是jQuery时重现吗?” 很抱歉,花了很长时间。

以下是HTML(略有简化):

<html>
  <head>
    <base target="_top">
  </head>
  <script>
  window.onload=function(){
  console.log('onload has run');
  google.script.run
  .withSuccessHandler(displayDates)
  .getDates();
  }
  function displayDates(datObj){
    var s='';
    gdateObj=datObj;
    for(var i=0;i<datObj.idA.length;i++){
      s+=datObj[datObj.idA[i]+'-html'];
    }
    s+='<br /><input type="button" value="Save Dates" onClick="saveChanges();" />';
    s+='<input type="button" value="Get Dates" onClick="getDates();" />';
    s+='<input type="button" value="Exit" onClick="google.script.host.close();" />';
    document.getElementById('dates').innerHTML=s;
    for(var i=0;i<datObj.idA.length;i++){
      document.getElementById(datObj.idA[i]).setAttribute("value",formatDateTime(new Date(datObj[datObj.idA[i]])));
    }
  }
  function formatDateTime(dt){
    if(dt && Object.prototype.toString.call(dt) === '[object Date]'){
      var M=dt.getMonth()+1;
      var d=dt.getDate();
      var h=dt.getHours();
      var m=dt.getMinutes();
      var s=dt.getSeconds();
      var MM=(M<10)?String('0'+M):String(M);
      var dd=(d<10)?String('0'+d):String(d);
      var hh=(h<10)?String('0'+ h):String(h);
      var mm=(m<10)?String('0'+m):String(m);
      var ss=(s<10)?String('0'+s):String(s);
      var ds=dt.getFullYear() + '-' + MM + '-' + dd + 'T' + hh + ':' + mm;
      return ds;
    }else{
      throw("Error: Parameter dt is not a valid date");
    }
  }
  </script>
  <body>
    <div id="dates"></div>
  </body>
</html>

和我的控制台日志:

Unrecognized feature: 'vibrate'.
userCodeAppPanel:2 Unrecognized feature: 'vibrate'.
userCodeAppPanel:3 onload has run
1995166154-warden_bin_i18n_warden.js:56 Net state changed from IDLE to BUSY
1995166154-warden_bin_i18n_warden.js:194 Co {message: "There was an error during the transport or process…this request. Error code = 10, Path = /wardeninit", name: "TransportError", stack: "TransportError: There was an error during the tran…/js/1995166154-warden_bin_i18n_warden.js:178:252)"}message: "There was an error during the transport or processing of this request. Error code = 10, Path = /wardeninit"name: "TransportError"stack: "TransportError: There was an error during the transport or processing of this request. Error code = 10, Path = /wardeninit↵    at new Co (https://docs.google.com/static/macros/client/js/1995166154-warden_bin_i18n_warden.js:178:339)↵    at Ho.q.Cd (https://docs.google.com/static/macros/client/js/1995166154-warden_bin_i18n_warden.js:186:350)↵    at Ai (https://docs.google.com/static/macros/client/js/1995166154-warden_bin_i18n_warden.js:76:228)↵    at zi (https://docs.google.com/static/macros/client/js/1995166154-warden_bin_i18n_warden.js:73:491)↵    at ui.m (https://docs.google.com/static/macros/client/js/1995166154-warden_bin_i18n_warden.js:73:438)↵    at Ai (https://docs.google.com/static/macros/client/js/1995166154-warden_bin_i18n_warden.js:76:228)↵    at zi (https://docs.google.com/static/macros/client/js/1995166154-warden_bin_i18n_warden.js:73:491)↵    at Ho.<anonymous> (https://docs.google.com/static/macros/client/js/1995166154-warden_bin_i18n_warden.js:185:159)↵    at on (https://docs.google.com/static/macros/client/js/1995166154-warden_bin_i18n_warden.js:143:304)↵    at po (https://docs.google.com/static/macros/client/js/1995166154-warden_bin_i18n_warden.js:178:252)"__proto__: C
1995166154-warden_bin_i18n_warden.js:56 Net state changed from BUSY to IDLE

这是电子表格中所有日期的屏幕外观:

enter image description here

这是当我单击指向javascript的链接时源面板的外观。

<!doctype html><style nonce="TqICcsqvIDjfixWz6NYEPlNwdL0">html, body, iframe {border: 0; display: block; height: 100%; margin: 0; padding: 0; width: 100%;}iframe#userHtmlFrame {overflow-y: scroll; -webkit-overflow-scrolling: touch;}</style><meta name="chromevox" content-script="no"><script type="text/javascript" src="/static/macros/client/js/2261581559-mae_html_user_bin_i18n_mae_html_user.js" nonce="TqICcsqvIDjfixWz6NYEPlNwdL0"></script>
<script nonce="TqICcsqvIDjfixWz6NYEPlNwdL0">maeInit_( true );</script><iframe id="userHtmlFrame" allow="accelerometer *; ambient-light-sensor *; autoplay *; camera *; encrypted-media *; fullscreen *; geolocation *; gyroscope *; magnetometer *; microphone *; midi *; payment *; picture-in-picture *; speaker *; usb *; vibrate *; vr *" src="/blank"></iframe><form id="example_form"></form>

0 个答案:

没有答案