I have a page that lists links to files on the clients local network, and when clicked on, the link launches a new browser window using
<script language='JavaScript'>
function openLocalFile( fileName )
{
var hwin = window.open( fileName, etc, etc );
// Insert some sort of test here to check if the page loaded or if
// an error was encountered loading the page.
}
</script>
<a href='#' onClick='javascript: openLocalFile("H:\directory\somefile.txt"); return false;'>Click to view</a>
I would like to be able to check if the window.open actually opened the document, or if a "The page cannot be displayed" error or such has been encountered. Ideally, then I could return my own error page so I can display a more informative message that fits the look and feel of my site.
Never mind ... it seems the window object has an onError method that allows you to specify a function to run in the event that an error occurs loading the page.
hwin = window.open( fileName, etc, etc );
hwin.onError = alert('The specified file was not found. Has it been renamed or removed?');
Obviously you can put in a better handler than the one I chose for this reply.
Bookmarks