gpt4 book ai didi

javascript - 谷歌表格中的 "Script App"是否会自动登录网站?

转载 作者:行者123 更新时间:2023-12-01 18:36:46 25 4
gpt4 key购买 nike

我正在尝试在 Google Sheets 脚本应用程序中实现此功能,但不确定如何使用 getElementById

网站

    <div id="loginusr">
<input type="text" value="" class="use inputCss" placeholder="Digite o nome do usuário">
<div id="loginpow">
<input type="password" value class="pow inputCss" placeholder="Por favor, digite sua senha">

<div id="loginbtn" class="hover">Login</div>

我的代码

    function test(){

var url = 'https://www.renovigi.solar/';

var html = "<script>window.open('" + url + "');google.script.host.close()</script>";

var userInterface = HtmlService.createHtmlOutput(html);

SpreadsheetApp.getUi().showModalDialog(userInterface, 'Opening website');


}

我尝试添加 document.getElementById("loginusr").Value = "TEST" 但随后收到消息

ReferenceError: "document" is not defined."

最佳答案

document.getElementById是客户端方法 - 您不能在服务器端 Apps 脚本代码部分中使用它

您可以在代码的 javascript 部分内使用它(在 <script> 标记内)。

但是,想想这个方法应该做什么 - 您想从您的网站访问某个元素吗?在这种情况下,您需要使用 html 嵌入网站的完整代码。您的 Apps 脚本项目的文件并创建 https://developers.google.com/apps-script/guides/web为了整合您的代码的服务器端和客户端。

另外:应该是 document.getElementById("loginusr").value ,不是document.getElementById("loginusr").Value

关于javascript - 谷歌表格中的 "Script App"是否会自动登录网站?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60022234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com