I was experimenting with Google Apps Script by adding HTML pages and was trying to navigate to a HTML view within my app using ScriptApp.getService().getUrl(). When I am adding a text link with the said code within the html page as:
<a href="<?= ScriptApp.getService().getUrl(); ?>?do=student-details">add user</a>
it works as expected. But if I try to do the same using JavaScript as:
document.getElementById('studentButton').addEventListener('click', e => {
const url = "<?= ScriptApp.getService().getUrl() ?>?do=student-details"
console.log(url)
window.location.href = url
})
it's giving Forbidden Error 403. If I click the URL on the console log, it's opening the desired page with no problem. Also if I try to open the same using window.open(url, '_blank'), then it is also working. Why this is happening and how to overcome this?