andyBlog [andy britcliffe]

Blogtastic

Detecting network activity with IE8 Beta 1

So I've been having a dig around the developer experience with the new IE8 beta 1 we released back at Mix 08 and one of the cool features I've come across is genuine network connectivity detection.

Previously with IE you were only able to detect if the user had set IE to offline mode explicitly and would not be able to detect if a network connect was or wasn't present.

However this has now all changed as calling alert(window.navigator.onLine) will give you a honest true or false as to whether there is network connectivity. Added to this is that IE8 gives you a couple of event handlers to notify the browser (and hence you webpage) when the connectivity status changes.

Here is a very simple example of a basic web page with the handlers wired up to alert on change of connection status:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Test IE8 Online/Offline notification</title>

    <script type="text/javascript" language="JavaScript">    
        function offline()
        {
            alert("offline with IE8");
        }
        
        function online()
        {
            alert("online with IE8");
        }  
    </script>

</head>
<body onoffline="offline()" ononline="online()">
    <p>Disconnect and reconnect your network to see the alert status</p>
</body>
</html>
Published Friday, May 23, 2008 8:18 PM by andybrit
Filed under: , ,

Comments

No Comments
Anonymous comments are disabled

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker