获取当前页面的网址 [英] get current page url

查看:125
本文介绍了获取当前页面的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用GAS HtmlService的Web应用程序中,我需要获取当前页面的url以在模板中构建新链接。



Web应用程序将运行在谷歌网站页面(GAS作为小工具),但也是独立的



我试着var pageUrl = document.location.href,然后在Html模板中使用pageUrl,如下所示。

 < a href =<?= pageUrl +?我知道这是错误的,但我迷路了,对不起。 item = xyz?> >项目xyz链接< / a> 

谢谢,Fausto

解决方案

 < a href =< / p>你可以通过ScriptApp获得一个webapp的url: ?= ScriptApp.getService()。getUrl()+?item = xyz?> >项目xyz链接< / a> 

您可以通过SitesApp在网站中获取网址:

  SitesApp.getActivePage()。getUrl()



<尽管我不认为这对于你所描述的内容实际上是有用的,因为你无法向它添加有用的查询参数。脚本在iframe中运行,因此虽然可以在客户端上使用document.location,但它无论如何不会对您有所帮助。 URL已被清理,服务ID已被删除。


On a web app using GAS HtmlService I need to get the url of current page to build a new link within a template.

The web app will run in a Google sites page (GAS as gadget) but also standalone

I am trying "var pageUrl = document.location.href" and then use pageUrl within a Html template like follow. I know it's wrong, but I am lost, Sorry.

<a href="<?= pageUrl + "?item=xyz" ?>" >Item xyz link</a>

Thanks, Fausto

解决方案

You can get the url for a webapp via ScriptApp:

<a href="<?= ScriptApp.getService().getUrl() + "?item=xyz" ?>" >Item xyz link</a>

and you can get the url in sites via SitesApp:

SitesApp.getActivePage().getUrl()

although I don't think that's actually useful for what you seem to be describing since you can't add useful query parameters to it. Scripts run in iframes, so although you can use document.location on the client, it won't help you anyways. The URL is sanitized and the service id is stripped out.

这篇关于获取当前页面的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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