Summary
I would like to prevent a user from navigating away from a page. The browser should prompt the user with a confirmation dialog when they try to leave the page.
Steps to reproduce
Code snippet:
st.markdown("""
<script>
window.addEventListener('beforeunload', function (e) {
e.preventDefault();
e.returnValue = '';
});
</script>
""", unsafe_allow_html=True)
Expected behavior:
The broser displays a confirmation dialog before leaving
Actual behavior:
Nothing happens
Debug info
- Streamlit version: (get it with
$ streamlit version
) - Python version: Streamlit, version 1.17.0
- Using PipEnv
- OS version: MacOS
- Browser version: Version 115.0.5790.170 (Official Build) (arm64)