?
Solved

navigator.online not working

Posted on 2012-09-14
9
Medium Priority
?
534 Views
Last Modified: 2012-09-20
Please see this code:

if (localStorage.SurveyCompleted == 'True') {
                if (navigator.onLine) {
                    window.location.href = "Splash.htm";
                }
                else {
                    pfShowNetworkErrAlert();
                }    
            }

I am faced with a very strange issue.
If i am using my website on 1024 x 768 or 1366 x 768, then the above function works as it should.

BUT, on 1920 x 1080, it always goes in the 'if' part even though my machine is NOT online.  What is this weird issue? How do I resolve it?
0
Comment
Question by:RTKHOT
  • 5
  • 4
9 Comments
 
LVL 10

Expert Comment

by:Pramod Kumar
ID: 38398387
Test this HTML:

<!DOCTYPE html>
<html>
<body>

<p id="demo">Click the button to see if the browser is online.</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction()
{
var a = "onLine: "+navigator.onLine;
var b = "<br>appCodeName: "+navigator.appCodeName;
var c = "<br>appName: "+navigator.appName;
var d = "<br>appVersion: "+navigator.appVersion;
var e = "<br>cookieEnabled: "+navigator.cookieEnabled;
var f = "<br>platform: "+navigator.platform;
var g = "<br>userAgent "+navigator.userAgent ;

var x = a+b+c+d+e+f+g;
document.getElementById("demo").innerHTML=x;
}
</script>

</body>
</html>

Open in new window

0
 

Author Comment

by:RTKHOT
ID: 38398424
I've requested that this question be deleted for the following reason:

wrong question
0
 

Author Comment

by:RTKHOT
ID: 38398415
PLEASE DO NOT DELETE THIS QUESTION.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:RTKHOT
ID: 38398417
pramodkrjsr =>

my browser shows online even though the network cable was unplugged
0
 
LVL 10

Expert Comment

by:Pramod Kumar
ID: 38398425
Your reason "wrong question" is not clear to me. You said your browser showing online even the network is unplugged...that means you still have the issue. Why you wanted to close this question. Did us got the solution?
0
 

Author Comment

by:RTKHOT
ID: 38398731
Please do not delete this question. it was an accident

we have 4 machines.

on 2 of them, the browser is returning online even though the network cable is unplugged. so what could this issue be?
0
 
LVL 10

Expert Comment

by:Pramod Kumar
ID: 38399574
may be connected via some other wireless network (wifi) may be.
0
 

Author Comment

by:RTKHOT
ID: 38409044
No i checked that. there is no other connection. That's why I am wondering what this odd issue is
0
 
LVL 10

Accepted Solution

by:
Pramod Kumar earned 820 total points
ID: 38417205
ok, now i know the answer.
Actually "navigator.onLine" is an offline APIs in HTML5.
But, this is  recently landed in Chrome.
You must ensure if this API is supported in your browser:

My result with various browsers
Firefox: 14.0.1 = NOT WORKED
IE8 = WORKED
Chrome 21.0.1180.89 m = WORKED

Some browser vendors detect whether you have network connectivity, others use the user selected "Work Offline" mode

You may also get more details here:
http://stackoverflow.com/questions/3181080/how-to-detect-online-offline-event-cross-browser/9677537#9677537
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question