문제

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;
}
도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top