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 htmlServiceZig Mandel– Zig Mandel2015-09-29 12:17:31 +00:00Commented Sep 29, 2015 at 12:17
-
you can check this thread with examples tom anage multiple screen in thmlservcie stackoverflow.com/a/25224762/3556215St3ph– St3ph2015-09-29 12:55:14 +00:00Commented Sep 29, 2015 at 12:55
-
thank you i was able to achieve my target using the above thread.kaushik dugar– kaushik dugar2015-09-30 09:27:58 +00:00Commented Sep 30, 2015 at 9: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.
1 Comment
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.
1 Comment
function url() {return ScriptApp.getService().getUrl();}. This is much simpler and less redundant. is't it?