Frage

Editing HTML content in Google Sites

I have a small project in mind but cant seem to get past this one obstacle. Having trouble getting the HTML content of this Google Sites Page and adding a single line too it. So if one would keep refreshing the page the 'Hello World' line would keep adding itself over and over. I have noticed that the original code that embeds the gadget gets altered quite a bit too.

function doGet() {
  var app  = UiApp.createApplication();
  var page = SitesApp.getActivePage();
  var html = page.getHtmlContent();
  var main = page.setHtmlContent(html + '<br>Hello World<br>');

  return app;
}
War es hilfreich?

Lösung

.getHtmlContent() will return all the html markup and tags. So, you're trying to set "Hello World" after all the tags have been closed.

Throw a Logger.log(html); in there to see what you need to get at and change. Ultimately you'll need to replace the text you want within the html instead of just adding a line to the end.

Andere Tipps

its by design that the html keeps chsnging every time you run it. your script permanently modifies the site. instead you need to publish a htnlservice appscript and insert it on the site.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top