I am working on an AngularJS app. I am trying to detect if the user is on the internet (vs just a network). In an attempt to do this, I thought I would fire off an $http.get to Google.com. I'm trying this:
myApp.controller('MyController', function($scope, $http) {
$scope.canConnectToInternet = null;
$scope.start = function() {
$http.get('http://www.google.com').then(function(result) {
console.log(result);
});
};
$scope.start();
});
Unfortunately, this code triggers the dreaded "XMLHttpRequest cannot load http://www.google.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. "
error. I understand this is a security mechanism. However, as an app developer, I feel there should be a way for me to explicitly bypass it.
How can I make a request to a web site just to detect if I'm on the internet?
Thank you!