screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script> <script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.development.js"></script> <script src="https://cdn.jsdelivr.net/npm/@babel/standalone@7.14.6/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel" data-presets="env,react"> const { useState, useEffect } = React; function App() { const [toastMessage, setToastMessage] = useState(""); useEffect(() => { const intervalId = setInterval(() => { window.parent.location.reload(); }, 7000); setToastMessage( `Page Reloaded Successfully at ${new Date().toLocaleTimeString()}!` ); return () => clearInterval(intervalId); }, []); const hideToast = () => { setToastMessage(""); }; useEffect(() => { if (toastMessage) { const timer = setTimeout(() => { hideToast(); }, 5000); return () => clearTimeout(timer); } }, [toastMessage]); return ( <div className="container"> <h1>React Js Auotmatic refresh or reload page</h1> {toastMessage && ( <div className="toast"> <div>{toastMessage}</div> <button onClick={hideToast}>X</button> </div> )} </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; position: relative; } h1 { text-align: center; } .toast { background-color: #f0f0f0; padding: 10px; margin-top: 10px; border-radius: 4px; display: flex; align-items: center; justify-content: center; position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); } .toast div { flex-grow: 1; } .toast button { background-color: transparent; border: none; color: #888; cursor: pointer; font-size: 14px; } </style> </body> </html>