'Google Apps Script - redirecting by «window.top.location.href» stop working
This construction doesn't work in my GAS project anymore to redirect browser:
return HtmlService.createHtmlOutput(`<script>window.top.location.href='${url}';</script>`);
This construction works:
return HtmlService.createHtmlOutput(`<script>window.location.href='${url}'</script>`);
But it hides real redirected page URL behind the script URL because we are changing not the ".top" window href.
Has anyone faced this problem too?
P.S.: I tested it on several people with Chrome browser - the same result.
Solution 1:[1]
I have been having the same issue... Noticed it a few weeks ago and just did a search and found this question on Stack Overflow. However, upon a further search it appears as though Google has disabled the ability to do this as per their September update:
https://developers.google.com/apps-script/releases
September 2021 September 1, 2021 In the HTML Service iframe sandbox, allow-top-navigation, which allows the content >to navigate its top-level browsing context, is restricted and not set as an >attribute in the sandbox. Instead, the allow-top-navigation-by-user-activation >attribute has been added to the sandbox.
If you need to redirect your script, add a link or a button for the user to take >action on.
Learn more about HMTL Service restrictions.
However, it appears to me like it still works in some circumstances. I have a application with about 30 pages or so and it appears on some pages it still works. Have not been able to find out the reason though.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | bad_coder |
