Apps Script .getActivePage() only returning “home”

2019-05-10 03:56发布

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

3条回答
Viruses.
2楼-- · 2019-05-10 04:30

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楼-- · 2019-05-10 04:38

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;
}
查看更多
一夜七次
4楼-- · 2019-05-10 04:39

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...

查看更多
登录 后发表回答