2016-12-27 135 views
0

我正在製作Google文檔的網絡應用程序,您可以將文檔的網址通過我自己的網站添加到SQL數據庫。我想要一個側邊欄,讓你輸入用戶名和密碼的形式,其中隱藏的輸入包含當前文檔的URL。更改側欄的內容

我已經成功地接受了隱藏的輸入。我知道如何從側欄的html頁面運行功能。我的問題在於功能...我希望有一些像document.sidebar.getUi().getElementById('URLinput').value = "the url";

我知道如何獲得網址。我不知道如何編輯邊欄的「body」。

這是我到目前爲止的代碼:

var doc = DocumentApp.getActiveDocument(); 
 
var link = doc.getUrl(); 
 

 

 

 
function addUrl() { //I have no idea how to do this part... 
 
    var html = HtmlService.createHtmlOutput('page'); 
 
    DocumentApp.getUi().showSidebar(html); 
 
} 
 

 
function onOpen() { 
 
    DocumentApp.getUi() // Or DocumentApp or FormApp. 
 
    .createMenu('Timklein') 
 
    .addItem('Show sidebar', 'showSidebar') 
 
    .addToUi(); 
 
} 
 

 
function showSidebar() { 
 
    var html = HtmlService.createHtmlOutputFromFile('page') 
 
    .setTitle('My custom sidebar') 
 
    .setWidth(700); 
 
    DocumentApp.getUi() // Or DocumentApp or FormApp. 
 
    .showSidebar(html); 
 
}
<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 
    <base target="_top"> 
 
</head> 
 

 
<body> 
 
    <h1>Timklein.tk webapp</h1> 
 
    <form action="mysite.com/adddoc.php" method="POST"> 
 
    <b>add to database...</b> 
 
    <br>username: 
 
    <input type="text" name="username"> 
 
    <br>password: 
 
    <input type="password" name="password"> 
 
    <br>Naam van het document: 
 
    <input type="text" size="2" name="docName"> 
 
    <br> 
 
    <input type="hidden" name="docLink" id="URLinput"> 
 
    <input type="submit" name="submit" value="send"> 
 

 
    </form> 
 
    <script> 
 
    google.script.run.doSomething(); 
 
    </script> 
 
</body> 
 

 
</html>

任何幫助將是非常感謝!

在此先感謝!

回答

0

您可以嘗試使用以下代碼行來獲取輸入值: document.getElementById('URLinput')。value =「the url」;

希望這會有所幫助!

0

您需要使用append()函數來添加一個腳本標記,該腳本標記在更改輸入的html頁面上運行一個函數。在showSidebar的功能中你把這個設置爲: html.append("<script>addURL(theURL);</script>"); 你在html頁面做一個功能: function addURL(url) { document.getElementById('urlinput').value = url; } 你就完成了!