Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <script> var txt = ""; function message() { try { adddlert("Welcome guest!"); } catch(err) { txt = "There was an error on this page.\n\n"; txt += "Click OK to continue viewing this page,\n"; txt += "or Cancel to return to the home page.\n\n"; if(!confirm(txt)) { document.location.href = "https://www.w3schools.com/"; } } } </script> <body> <h2>JavaScript Error Handling</h2> <input type="button" value="View message" onclick="message()" /> </body> </html>