File size: 831 Bytes
be3349a
 
 
aa0b520
be3349a
af0a2a3
 
 
 
50891f0
 
af0a2a3
 
600b4d9
af0a2a3
50891f0
 
af0a2a3
 
50891f0
 
 
 
 
be3349a
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import streamlit as st

def main():
    st.title('Message Receiver')

    # Display a placeholder for the received message
    received_message_placeholder = st.empty()

    # JavaScript code to handle messages received from the parent iframe
    js_code = """
    <script>
    // Function to handle messages received from the parent iframe
    const receiveMessageFromParent = (event) => {
        // Update the Streamlit title with the received message
        document.title = 'Message Receiver - ' + event.data.message;
    };

    // Add event listener to listen for messages from the parent iframe
    window.addEventListener('message', receiveMessageFromParent);
    </script>
    """

    # Write the JavaScript code to the Streamlit app
    st.write(js_code, unsafe_allow_html=True)

if __name__ == '__main__':
    main()