我已经搜索了许多论坛,我很有信心这将是一个不,但我想我会开放给社区,以防万一;)
我的任务是在我们的谷歌网站页面上创建一个工具,在访问页面后记录员工的访问时间。它有助于确认文档访问和活动日志的遵从性。如果一个iFrame与它所在的页面位于同一个域上,那么很容易从框架内查询父页面的URL,但是安全性限制了跨域或子域。
我希望我将谷歌应用程序脚本嵌入到Google站点页面中,这将给我更多的选择。到目前为止,我已经尝试过命令document.referrer,parent.document.location,parent.window.document.location,parent.window.location,parent.document.location.href,以及窗口和文档透视图中的相同命令。他们的反应都一样:
https://n-labp6vtqrpsdn12345neycmicqw7krolscvdkda-0lu-script.googleusercontent.com/userCodeAppPanel当我想:
https://sites.google.com/mysite.com/mysite/test/test3谷歌的老手们还有其他的窍门吗?
编辑:我刚刚尝试通过一个html链接传递变量,即Google站点上的应用程序脚本的Google图像占位符,并得到了一点进展。您知道,如果我在一个单独的窗口中运行url,我可以运行这个url:https://script.google.com/a/macros/coordinationcentric.com/s/AKfycbxDX2OLs4LV3EWmo7F9KuSFRljMcvYz6dF0Nm0A2Q/exec?test=hello&test2=howareyou,并获得变量test1和test2。如果我试图将该URL嵌入到Google站点的HTML页面中,则会引发以下混合内容错误:
trog_edit__en.js:1544 Mixed Content: The page at
'https://sites.google.com/a/mysite.com/mysite/test/test3' was loaded over HTTPS, but requested an insecure image 'http://www.google.com/chart?chc=sites&cht=d&chdp=sites&chl=%5B%5BGoogle+Apps+Script%27%3D20%27f%5Cv%27a%5C%3D0%2710%27%3D499%270%27dim%27%5Cbox1%27b%5CF6F6F6%27fC%5CF6F6F6%27eC%5C0%27sk%27%5C%5B%22Apps+Script+Gadget%22%27%5D%27a%5CV%5C%3D12%27f%5C%5DV%5Cta%5C%3D10%27%3D0%27%3D500%27%3D197%27dim%27%5C%3D10%27%3D10%27%3D500%27%3D197%27vdim%27%5Cbox1%27b%5Cva%5CF6F6F6%27fC%5CC8C8C8%27eC%5C%27a%5C%5Do%5CLauto%27f%5C&sig=TbGPi2pnqyuhJ_BfSq_CO5U6FOI'. This content should also be served over HTTPS.有人尝试过这种方法吗?
发布于 2019-05-01 03:40:32
简而言之,我知道在Google站点中不可能调查来自iFrame的父URL。
iframes/embedded内容被托管在整个地方,与站点本身是分开的。同样的-原产地规则阻止检查,因为你已经找到了。
你的第一个网址“https://n-labp...googleusercontent.com.”脚本本身所在的位置。脚本的任何输出,如HTML,似乎都来自这里。
您可以使用embed函数将HTML和javascript直接嵌入到站点中。如果你对此进行调查,你会发现它被托管在类似于“https://1457130292-atari-embeds.googleusercontent.com.”的地方。
调用父级将始终提供这个基于*-atari的URL,而不是它所在的实际页面。
一个相当轻量级的解决方案是将两者结合使用。使用简单的doGet pings并在应用程序脚本中处理工作。
在您的站点上,使用嵌入功能插入:
<!DOCTYPE html>
<html>
<body onbeforeunload="return depart()">
<script>
var page = "testpage"; // manually set a name for each page you paste this code in to
var script = "https://script.google.com/macros/s/... your script, ending with exec ...";
fetch(script+"?page="+page+"&direction=arrive");
function depart(){
fetch(script+"?page="+page+"&direction=depart");
}
</script>
</body>
</html>然后在你的应用程序脚本中:
function doGet(e){
var httpParams = e.parameter ? e.parameter : "";
// params is an object like {"page": "testpage1", "n": "1"}
var getPage = httpParams.page ? httpParams.page : "";
var getDirection = httpParams.direction ? httpParams.direction : "";
/* Handle it as you please, perhaps like: */
var user = Session.getActiveUser().getEmail();
/* maybe use a temporary active key if open to non-Google users */
/* first-time Google users will have to authenticate, so embed one frame somewhere full-size maybe, or just tell users to go to the script's link */
/* hand off to a helper script */
var time = new Date();
var timeUTC = time.toUTCString(); // I like UTC
doSomethingWithThis(user, direction, timeUTC);
/* etc... */
/* Return some blank HTML so it doesn't look too funny */
return HtmlService.createHtmlOutput("<html><body></body></html>");
}然后发布为一个网络应用程序。如果您将使用临时活动密钥而不是Google帐户,那么脚本将以您的身份运行,并且任何人都可以使用,甚至匿名。
你可能已经解决了这个问题,但我希望它能对其他偶然发现它的人有用!
https://stackoverflow.com/questions/46818753
复制相似问题