I have multiple html files in my script project.I want to link different html files using the anchor tag.Like a href="link to another html file in the same app script project". How do i achieve this? The file must reload on the same window.
-
doubt its possible. needs to be served by htmlService – Zig Mandel Sep 29 '15 at 12:17
-
you can check this thread with examples tom anage multiple screen in thmlservcie http://stackoverflow.com/a/25224762/3556215 – St3ph Sep 29 '15 at 12:55
-
thank you i was able to achieve my target using the above thread. – kaushik dugar Sep 30 '15 at 09:27
2 Answers
Assuming the app is served via HtmlService, we can use script runners to retrieve new html from the project files. Content is just removed / added to existing elements while toggling their visibility in the single page app instead the browser doing an actual window reload.
If you don't need the "pages" to be reloaded when they are clicked, you can just load all the html upfront instead.

- 5,031
- 3
- 30
- 44
Suppose there is page1(html file) and page2(html file). Change the Code.gs as follows:
function doGet(e) { Logger.log( Utilities.jsonStringify(e) ); if (!e.parameter.page) { return HtmlService.createTemplateFromFile('page1').evaluate(); } return HtmlService.createTemplateFromFile(e.parameter['page']).evaluate(); } function getScriptUrl() { var url = ScriptApp.getService().getUrl(); return url; }
Add
<base target="_top">
tag to every html file.Linking to another html from html will be possible in a follwing way:
<?var url = getScriptUrl();?>window.top.location.href = '<?!=url?>?page=page2';
or
<?var url = getScriptUrl();?><a href = '<?!=url?>?page=page2'>Jump to page2</a>
See here for more information.

- 390
- 2
- 15
-
you could do, `function url() {return ScriptApp.getService().getUrl();}`. This is much simpler and less redundant. is't it? – Mahhdy Jun 07 '19 at 17:31