Working with jQuery when there is no Internet connection
Yes, it's possible. You've mentioned that you downloaded the file - that's a good first step, but you also have to change all the href
and src
references.
For example,
<link rel="stylesheet" href="http://jquery.com/jquery-wp-content/themes/jquery/css/base.css?v=1">
should become
<link rel="stylesheet" href="base.css">
Also remember to get the offline version of the jQuery JS library, too:
Download jquery.js, put it in your root folder & reference it:
<script src="jquery-1.9.1.min.js"></script>
And if you want it in a subdirectory:
<script src="[subdirectory-name]/jquery-1.9.1.min.js"></script>
Remember that both files need to be offline and in your working local directory. This means that you cannot remove the stylesheet nor the jQuery JS library. Keep both of them, in the local formats I've mentioned above.
Also, putting the <script>
tag in the <head>
is bad practice; move it just before the </body>
tag instead.
Your code should now look (in short, note that I haven't put much) like:
...
<html class="no-js" lang="en-US">
<head>
...
<link rel="stylesheet" href="base.css">
...
</head>
<body>
...
<script src="jquery.min.js"></script>
</body>
</html>
Again, make sure that base.css
and jquery.min.js
are the exact file names and are in the same folder as this .html
file
Check if no Internet Connection - Popup - Windows 10 App(Javascript)
you can use the NetworkConnectivityLevel, NetworkInformation.getInternetConnectionProfile and getNetworkConnectivityLevel to do this, and show the information with a MessageDialog in the default.js like this:
var connections = Windows.Networking.Connectivity.NetworkInformation.getInternetConnectionProfile();
if (connections != null) {
var networkConnectivityLevel = connections.getNetworkConnectivityLevel();
if (networkConnectivityLevel == Windows.Networking.Connectivity.NetworkConnectivityLevel.internetAccess) {
var msg = new Windows.UI.Popups.MessageDialog("Internet access OK.");
} else if (networkConnectivityLevel == Windows.Networking.Connectivity.NetworkConnectivityLevel.constrainedInternetAccess) {
var msg = new Windows.UI.Popups.MessageDialog("Limited internet access.");
} else if (networkConnectivityLevel == Windows.Networking.Connectivity.NetworkConnectivityLevel.localAccess) {
var msg = new Windows.UI.Popups.MessageDialog("Local network access only.");
} else if (networkConnectivityLevel == Windows.Networking.Connectivity.NetworkConnectivityLevel.none) {
var msg = new Windows.UI.Popups.MessageDialog("No internet access.");
}
msg.showAsync();
} else {
var msg = new Windows.UI.Popups.MessageDialog("No internet access.");
msg.showAsync();
}
Check Internet connectivity with jquery
$.get()
returns a jqXHR object, which is promise compatible - therefore no need to create your own $.Deferred
.
var check_connectivity = {
...
is_internet_connected: function() {
return $.get({
url: "/app/check_connectivity/",
dataType: 'text',
cache: false
});
},
...
};
Then :
check_connectivity.is_internet_connected().done(function() {
//The resource is accessible - you are **probably** online.
}).fail(function(jqXHR, textStatus, errorThrown) {
//Something went wrong. Test textStatus/errorThrown to find out what. You may be offline.
});
As you can see, it's not possible to be definitive about whether you are online or offline. All javascript/jQuery knows is whether a resource was successfully accessed or not.
In general, it is more useful to know whether a resource was successfully accessed (and that the response was cool) than to know about your online status per se. Every ajax call can (and should) have its own .done()
and .fail()
branches, allowing appropriate action to be taken whatever the outcome of the request.
Related Topics
IE8 Alternative to Window.Scrolly
Ie Not Allowing Onclick Event on Dynamically Created Dom 'A' Element
Setting Multiple Style.Background Values
Update Three.Js Raycaster After CSS Tranformation
Tinymce: How to Display All Toolbars on a Single Row
Rotating a Div How to Set Around Which Point to Rotate
Implementing Flipcard on Click Instead of on Hover
How to Add a Drop Shadow to Chart.Js Line Chart
Show One Bootstrap Carousel Item in Mobile
Change CSS of the Add Form Using Jqgrid
Save Images After Using CSS Filter
How to Remove the White Border from Chart.Js Pie Chart
Jquery Animate Top (From Bottom to Top)
How to Remove an Important CSS Property
How to Animate the Opacity of the Background of a Div
How to Change Url in Browser Without Navigating Away from Page