更改侧栏的内容

问题描述:

我正在制作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>

任何帮助将是非常感谢!

在此先感谢!

您可以尝试使用以下代码行来获取输入值: document.getElementById('URLinput')。value =“the url”;

希望这会有所帮助!

您需要使用append()函数来添加一个脚本标记,该脚本标记在更改输入的html页面上运行一个函数。在showSidebar的功能中你把这个设置为: html.append("<script>addURL(theURL);</script>"); 你在html页面做一个功能: function addURL(url) { document.getElementById('urlinput').value = url; } 你就完成了!