Results 1 to 3 of 3

Thread: Detecting page load errors after window.open

  1. #1
    Join Date
    Jul 2005

    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

    <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.


    <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.

    Any suggestions would be appreciated.

  2. #2
    Join Date
    Jul 2005
    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.

  3. #3
    Join Date
    Jul 2005
    Okay, I feel silly for reopening the question. It seems my onError stuff gets run all the time, and not just on an error.

    Shamefully defeated.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center