1

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.

Jason Spence
  • 472
  • 5
  • 16

3 Answers3

1

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.

Omar Dulaimi
  • 846
  • 10
  • 30
1

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).

Zanon
  • 29,231
  • 20
  • 113
  • 126
0

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.

Sebastian Benz
  • 4,238
  • 1
  • 21
  • 17