1

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.

3
  • doubt its possible. needs to be served by htmlService Commented Sep 29, 2015 at 12:17
  • you can check this thread with examples tom anage multiple screen in thmlservcie stackoverflow.com/a/25224762/3556215 Commented Sep 29, 2015 at 12:55
  • thank you i was able to achieve my target using the above thread. Commented Sep 30, 2015 at 9:27

2 Answers 2

2

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.

Sample code

Live demo

Sign up to request clarification or add additional context in comments.

1 Comment

I liked your approach. Great
1
  1. 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;
    }
    
  2. Add <base target="_top"> tag to every html file.

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

you could do, function url() {return ScriptApp.getService().getUrl();}. This is much simpler and less redundant. is't it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.