Apps Script .getActivePage() only returning “home” page

匿名 (未验证) 提交于 2019-12-03 01:34:02

问题:

Is anyone else having trouble with SiteApps.getActivePage()? for me it's only returning the home page, not the active page.

回答1:

getActivePage is meant to work when you embed the published gadget in Google Sites page. It will return the page in which the GAS Gadget is embedded, otherwise it will return null

Here is a sample code which works perfect for me in Google Sites Apps Script Gadget.

function doGet(e) {   var app = UiApp.createApplication();   app.add(app.createLabel('Page name: '+SitesApp.getActivePage().getName()));   app.add(app.createLabel('Url: '+SitesApp.getActivePage().getUrl()));   return app; } 


回答2:

When directly embedding a gadget into a sites page, this seems to work as expected; however, when copying a page, it appears to fail -- perhaps this fits your scenario?

There's a pending apps-script issue (572) for pages copied from other pages which mentions:

getActivePage() called inside gadget returns the home page of the site



回答3:

The problem occurs whenever you setHtmlContent() on the page, the original embedding HTML code gets modified and the app stops behaving normally. It then returns the home page of the site whenever you getActiveSite() it...

It's really annoying and I'm quite disappointed about how long google is taking to fix this...



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!