This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createRequest() { | |
var request = null; | |
try { | |
request = new XMLHttpRequest(); | |
} catch (tryMS) { | |
try { | |
request = new ActiveXObject("Msxml2.HTTPRequest"); | |
} catch (otherMS) { | |
request = new ActiveXObject("Microsoft.XMLHTTP"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.history.back(); | |
window.history.forward(); | |
window.history.go(); //optionally give a number. -1 = back, 1 = forward | |
var allEntries = window.history.length; //entry length | |
var currentState = window.history.state; | |
history.pushState(, "Introduction to History API", "working.html"); | |
history.replaceState(, "Briefs on History API", "current.html"); | |
history.onpopstate = function() { | |
console.log("It has navigated to a different page"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.URL = window.URL || window.webkitURL; // Take care of vendor prefixes. | |
var xhr = new XMLHttpRequest(); | |
xhr.open('GET', '/path/to/image.png', true); | |
xhr.responseType = 'blob'; | |
xhr.onload = function(e) { | |
if (this.status == 200) { | |
var blob = this.response; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sendForm(form) { | |
var formContent = new FormData(form); //Get existing form content. Optional argument | |
formContent.append("hiddenId", "1234"); | |
formContent.append("iceCream", "Vanilla"); | |
formContent.append("currentLocation", "1223084.284|1209843.239"); | |
var progressBar = document.querySelector("progress"); | |
var xhr = new XMLHTTPRequest(); | |
xhr.open("POST", "server.php", true); | |
xhr.send(formContent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function upload(blobOrFile) { | |
var xhr = new XMLHttpRequest(); | |
xhr.open('POST', '/server', true); | |
xhr.onload = function(e) { console.log("Upload has finished."); }; | |
xhr.send(blobOrFile); | |
} | |
document.querySelector('input[type="file"]').addEventListener('change', function(e) { | |
var blob = this.files[0]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var connection = new WebSocket('ws://html5rocks.websocket.org/echo', ['soap', 'xmpp']); | |
connection.onerror = function (error) { | |
console.log('WebSocket Error ' + error); | |
}; | |
connection.onmessage = function (e) { | |
console.log('Server: ' + e.data); | |
}; | |
function sendData(type, content) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB; | |
window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.msIDBTransaction; | |
window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.msIDBKeyRange; | |
if(!window.indexedDB) { | |
console.log("IndexDB is not supported on your browser"); | |
} | |
function reportError(event) { | |
console.log("Error with Database. " + event.target.errorCode); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function gotLocation(position) { | |
console.log("I am at latitude " + position.coords.latitude + ", longitude " + position.coords.longitude + ", and accurate within " + position.coords.accuracy + " meter(s)."); | |
} | |
function handleLocationError(event) { | |
switch(event.errorCode) { | |
case 0: | |
console.log("We have an unknown error..."); | |
break; | |
case 1: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CACHE MANIFEST | |
CACHE: #Explicitly Cached after first download | |
sample1.png #Use version number to notify update/modification on file | |
sample2.png | |
NETWORK: #Items that must be retrieved from the server, regardless of the connection | |
sample3.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var serverEvent = new EventSource("http://example.com/eventsource.php"); //CORS is supported | |
serverEvent.onerror = function(event) { | |
console.log(event.target.errorCode); | |
}; | |
serverEvent.onopen = function() { | |
console.log("Connection has been established"); | |
}; |
OlderNewer