Getting the javascript “document HTML DOM” info wi

2019-06-10 10:47发布

问题:

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.

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) 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?

回答1:

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.

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.