screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script> <!---this is used to compile on run time---> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> </head> <body> <h3> React Js Close Window</h3> <div id="app"></div> <script type="text/babel"> const { useState } = React; const { render } = ReactDOM; function App() { const [result, setResult] = useState(""); const openWindow = () => { const url = "https://fontawesomeiocns.com"; const windowName = "myWindow"; const windowSize = "width=500,height=300"; setResult(window.open(url, windowName, windowSize)); }; const closeWindow = () => { result.close(); setResult(null); }; return ( <div > <button onClick={openWindow}>Open window</button> <button onClick={closeWindow} disabled={!result}>Close window</button> </div > ); } render(<App />, document.getElementById('app')); </script> </body> </html>