Can anyone point me in the right direction? I'm building a landing page that is supposed to store the current page URL with query strings to local storage. I've looked all over, but can't find a solution that will keep my AMP page valid.
3 Answers
I know this is a 3 year old question, but what you're trying to accomplish is doable through the use of the amp-script component.
You can read up here: https://amp.dev/documentation/components/amp-script/
Hope this helps somebody in the future.

- 846
- 10
- 30
Nowadays you can use for custom JS and access the localStorage, but as far as I know, you can't access the page URL directly.
Look at this compatibility table: https://github.com/ampproject/worker-dom/blob/main/web_compat_table.md
Document.location
is marked as false.
I'm working in an AMP project that needed the current page URL. What I did was to save the URL as an attribute and use a custom JS to read from this attribute (my pages are rendered in the server, so I can add this info there).

- 29,231
- 20
- 113
- 126
This is not possible with AMP as you can't run custom Javascript. This means you won't be able to read from local storage either.

- 4,238
- 1
- 21
- 17
-
Thank you for your response @sebsdtian-benz. – Jason Spence Dec 07 '17 at 16:23
-
2But amp-user-notification is setting information inside, why can't we do the same? – SeikoTheWiz Feb 20 '18 at 11:21
-
This answer is outdated. Nowadays you can run custom JS and access the localStorage with AMP – Zanon Apr 14 '21 at 10:05