Is there way to send a user to a web page programmatically without the user clicking anything?
My use case is that a user enters some data in a form and clicks a “Submit” button. The Streamlit application does some processing (e.g. creating the user record in a database, etc.) and redirects the user to another web page. The destination URL will be determined by the data entered into the form. Ideally, I could optionally open a new tab or browser window for the destination URL. The destination URL is not necessarily another Streamlit app.
While I could create a button or markdown link with a hyperlink (per some other articles) and have the user click, this is an extra step that I would like to avoid.
Seems like a common use case and I may be missing something obvious in the docs or a common workaround. Any help would be appreciated.
This does not work because there is a fundamental misunderstanding about how Streamlit works.
Streamlit consists of a frontend and backend part.
Any interaction with streamlit must be done via the browser or browser APIs.
Anything trying to bypass this, may work on your local computer, but will fail as soon as streamlit is hosted, i.e. streamlit no longer runs on the same computer as the browser.
What happens when webbrowser is used? A browser is started on the computer on which the python application is running. But there is no browser on streamlit cloud and even if there was, it would be the wrong computer.
I’m trying to do the same thing, but open in a new tab. Not having much luck with the new tab part.
Unfortunately, I don’t know hardly any HTML or javascript, so if anyone knows of something I can add to the html given above or javascript to do this, I would be eternally grateful!
JS I’ve tried (found via google): st_javascript(f'window.open({url}, "_blank", "location=yes,height=570,width=520,scrollbars=yes,status=yes");')
But that seems to do nothing at all.
st_javascript(f'window.open("{url}", "_blank");') works!
It helps to remember all the quotes.
I hope this helps someone else! (edited - note that the above produces an error, but I found the issue - apparently it needs to return something; I’m returning the parent url below… but ignoring the return value.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.