获取javascript“文档HTML DOM” Google Apps脚本中的信息 [英] Getting the javascript "document HTML DOM" info within Google Apps Script

查看:91
本文介绍了获取javascript“文档HTML DOM” Google Apps脚本中的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在(Episerver)页面中嵌入了Google电子表格,电子表格是可编辑的。我在工作表中也有一个触发器onEdit。当运行该脚本'onEdit'时,我想使用document.getElementsByClassName()。innerHTML从当前页面获取信息以获取当前情况的上下文,这意味着获取当前登录的用户名,该用户名显示在元素中的部分。

I'm having a Google spreadsheet embedded in an (Episerver) page and the spreadsheet is editable. I also have a trigger onEdit in the sheet. When running that script 'onEdit' I'd like to get the info from current page using "document.getElementsByClassName().innerHTML" to get the context of the current situation, meaning fetching the username that is currently logged in that is displayed in the section within an element.

我收到错误'文档未定义',我明白了。这只是在网站上运行脚本作为纯JavaScript。使用GAS URLFetchApp没有成功,因为它没有在当前用户登录的情况下获取当前页面。正如我所看到的,我有两种可能的选择:

I'm getting the error 'document is not defined' and I got the reason. This is working just running the script as a pure javascript on the site. There is no success using GAS URLFetchApp since it not fetching the current page with the current user logged in. As I see it I have two possible options:

a)是否存在无论如何在Google Apps脚本中使用HTML DOM(文档...)?
b)我可以获取当前页面而不是在Google Apps脚本中获取新网址吗?

a) Is there anyway to use HTML DOM (document...) within Google Apps Script? b) Can I fetch current page instead of fetching a new URL in Google Apps Script?

推荐答案

A)我认为您唯一的选择是 XML服务。< br>
B)我不相信,因为脚本是自包含的,并且没有能力与浏览器交互。您需要知道一个URL才能获取它。

A) I think your only option here is to us the XML service.
B) I don't believe so, as the script is self contained, and doesn't have the ability to interact with the browser. You need to know a URL in order to fetch it.

但是,你提到你想要做的部分是获取当前登录的用户,所以也许你可能对'。getActiveUser()'方法?这可能是一个潜在的解决方案。

However, you mention that part of what you'd like to do is fetch the user that is currently logged in, so perhaps you might be interested in the '.getActiveUser()' method? It might be a potential solution.

这篇关于获取javascript“文档HTML DOM” Google Apps脚本中的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆