New tab opens locally but not when deployed

Hi @kaankorkmaz

There’s a related conversation here and from this conversation I proposed a tweak as follows:

Code

The following code will open a new page upon clicking on the button:

import streamlit as st
from streamlit.components.v1 import html

def open_page(url):
    open_script= """
        <script type="text/javascript">
            window.open('%s', '_blank').focus();
        </script>
    """ % (url)
    html(open_script)

st.button('Open link', on_click=open_page, args=('https://streamlit.io',))

Hope this helps!

Best regards,
Chanin

2 Likes