在同一浏览器的新选项卡中显示数据[工作代码]

时间:2017-06-09 10:42:46

标签: javascript html google-apps-script google-sites

我有一个Google脚本,显示来自Google云端硬盘的数据列表,这就是它的样子。

enter image description here

此代码非常完美,只需要IContextindex.html,这里是两个代码。 (因此,对于那些在您的网站中使用谷歌应用程序脚本的人来说,这将有所帮助。)

的index.html

code.gs

code.gs

<!DOCTYPE html>
<html>
<head>
<style>
  .my_text
     {
        font-family:    Tahoma;
        font-size:      13px;
        font-weight:    normal;
     }
</style>

<base target="_top">

<script>
function displayMessage() 
{
        var searchTerm;
        searchTerm = document.getElementById('idSrchTerm').value;
        console.log('searchTerm: ' + searchTerm );
        google.script.run.withSuccessHandler(handleResults).processForm(searchTerm.replace("'","\'")); 
}            
        function handleResults(results){      
        var length=results.length;
        var table = document.getElementById("output");
        var count = document.getElementById("count");

             for(var i=0;i<length;i++)
             {
                var item=results[i];
                item=item.split("|~|");
                count.innerHTML = "Total Records Found : " + length;
                table.innerHTML  +="</br><a href='"+item[1]+"' target='_blank'>"+item[0]+"</a></br>  <B>Owner: </B>" +item[3]+ "</br><B>Last modified: </B>"+item[2]+ "</br> <B>File Size: </B>"+item[4]+"</br>";           
             }

}

function clearBox(elementID)
{
        document.getElementById("output").innerHTML = "";
        document.getElementById("count").innerHTML = "";
}
</script>

<style>
table, th, td 
{
    border: 1px solid black;
}
</style>

</head>

<body>


<div class="container">
       <p class = "my_text">Search File : <input type="text" id="idSrchTerm" name="search" class = "my_text">
       <input type="button" value="Search Drive" name="submitButton" class = "my_text" onClick="clearBox(); displayMessage();"/>
</div> 

<div id = "count" class = "my_text"></div>
<div id ="output" class = "my_text">

</div>

</body>
</html>

我唯一的目标是如何在function doGet(e) { // main function var template = HtmlService.createTemplateFromFile('index.html'); return template.evaluate().setTitle('Search Drive').setSandboxMode(HtmlService.SandboxMode.IFRAME); } function SearchFiles(searchTerm) { var searchFor ="fullText contains '" + searchTerm + "'"; var names = []; var files = DriveApp.searchFiles(searchFor); while (files.hasNext()) { var file = files.next(); var fileId = file.getId(); var lm = file.getLastUpdated(); var OType = file.getOwner().getName(); var fsize = file.getSize() var name = file.getName()+"|~|"+file.getUrl()+"|~|"+lm+"|~|"+OType+"|~|"+fsize; names.push(name); Logger.log(file.getUrl()); } return names; function processForm(searchTerm) { var resultToReturn; Logger.log('processForm was called! ' + searchTerm); resultToReturn = SearchFiles(searchTerm); Logger.log('resultToReturn: ' + resultToReturn); return resultToReturn; } } 中显示结果?我的意思是我会在文本框中键入任何字符串,然后单击按钮然后就可以了!输出将显示在新窗口中,例如New Window

TYSM将来的帮助。

0 个答案:

没有答案