Detecting page load errors after window.open
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
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.
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.
Any suggestions would be appreciated.
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.
Sorry to have bothered you.
Okay, I feel silly for reopening the question. It seems my onError stuff gets run all the time, and not just on an error.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)