Hi,
I am setting the URL in IFRAME.
I want to check if url exists or not before setting.
How can i detect to avoid error.
Hi makenzi.exc,
Refer below eaxmple.
HTML
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <style type="text/css"> body { font-family: Arial; font-size: 10pt; } </style> </head> <body> <iframe id="frame"></iframe> <script type="text/javascript"> window.onload = function () { var url ="https://www.aspsnippets.com/"; var request; if (window.XMLHttpRequest) { request = new XMLHttpRequest(); } else { request = new ActiveXObject("Microsoft.XMLHTTP"); } request.open("GET", url, false); request.send(); if (request.status === 404) { alert("The page is not available."); } else { document.getElementById("frame").src = url; } }; </script> </body> </html>
Demo
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.