How to redirect streamlit to a external url without open a new tab?

Hi All,

I have tried all the methods posted here to redirect to an external url. But all of them will open a new tab. Is there any way to redirect to url from the same tab of streamlit? Thank you!

1 Like
import streamlit as st
import streamlit.components.v1 as components

# embed streamlit docs in a streamlit app
components.iframe("https://www.baidu.com")
1 Like

Thank you for your response! I think iframe will embed the external url in the current streamlit page. But I want to redirect the whole streamlit page to the external page. for example, the current streamlit page has its url like: http://localhost:8501 to https://www.baidu.com on the same tab without opening a new tab. Is there any solution for it? thank you again!

I think you can do this with a HTML link and setting the link target. E.g.:

st.markdown('<a href="..." target="_self">...</a>', unsafe_allow_html=True)

But note that on Streamlit Cloud, this may not work perfectly in some cases. (The app is shown within an iframe on Streamlit Cloud and some websites can’t be opened within an iframe. That’s why we set the default link target to _blank in the first place so that the link always opens in a new tab.)

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.