htmltemplatesgoogle-apps-scriptweb-applicationsanchor

Anchor link to app with parameters, google apps script


I have the following anchors in my html template:

<a href="<?!= ScriptApp.getService().getUrl() ?>"><button>All Feedback</button></a>
<a href="<?!= ScriptApp.getService().getUrl()+"&filter=bomgar" ?>"><button>Bomgar Feedback</button></a>
<a href="<?!= ScriptApp.getService().getUrl()+"&filter=tickets" ?>"><button>Ticket Feedback</button></a>

When navigating to the links with parameters, the "&" and "=" symbols are %26 and %3d in the url. Is there a way to prevent this from happening ?


Solution

  • To add GET parameters to a URL, you should use the ? character to introduce them (instead of the & character). The ampersand is used to add multiple variables. So your URL should look like this.

    http://script.google.com/[.......]/exec?variable=data&otherVariable=otherData
    

    So since you didn't have the ?, the URL was sanitized to eliminate those characters.

    This web app that I made illustrates the difference.

    <a href="<?= ScriptApp.getService().getUrl()+"?filter=bomgar" ?>"><button>Bomgar Feedback</button></a>