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!

import streamlit as st
import streamlit.components.v1 as components

# embed streamlit docs in a streamlit app

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

1 Like