Import url to string for reference of where app is called from

get_url_hash only retrieves the text after the hash and since the webpages I want to embed my app in don’t have any I can’t reference the webpage that is accessing the hash.

I just want to be able to import the text after the last / or the whole url
to use as a reference

anvil.server.get_app_origin() gives me the app url but that is the same irrespective of the webpage it is being called from.

Thank you,

Welcome to the Anvil Forum, @lisajwright21.

By default, every Anvil app is a “single-page web app”. That is, there is only one URL for the entire app. When the app, running inside the browser, changes to a new Form, it literally re-writes the in-browser page on-the-fly, entirely inside the browser. This does not change the page’s URL.

If you want your app’s pages to have individual URLs, you may want to look at this post:

Routing, navigation with URL Hash

The authors have set up a framework that simulates distinct URLs, within the Anvil app, and lets them be used as if they were “real”, traditional URLs.

I might be misunderstanding… but is the question something like…

If my app is embedded in a web page inside an iframe, then how do I access the URL of the page that is embedding my anvil app?

1 Like

Yes this indeed. I want to be able to embed an app that I have written in more than one page and I want to know which page it has been used from.

lets say
page 1 is https://foo.fudge.com
page 2 is https://chocolate.biscuit.co.uk

both have instances of my app (which is really simple and just allows people to type messages to the webpage owner) which are then read by another app and I want to select which messages came from which page.

this might help:

Thank you for all your help. I am a real beginner. I tried to use the document.referrer but I wasn’t sure how to bring this into the anvil app.

I basically need some help replacing the command that I did have which worked

h = get_url_hash()

feeding h into my anvil functions etc with something that looks like

h = get_url

but I know it isn’t that simple.

Thank you - I have now been able to get the url

Great. What was your solution?

1 Like