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.
Google AMP - Save current page URL to local storage
886 Views Asked by Jason Spence AtThere are 3 best solutions below
On
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.
On
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).
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.