function getPage(url, from, to) { var cached=sessionStorage[url]; if(!from){from="body";} // default to grabbing body tag if(to && to.split){to=document.querySelector(to);} // a string TO turns into an element if(!to){to=document.querySelector(from);} // default re-using the source elm as the target elm if(cached){return to.innerHTML=cached;} // cache responses for instant re-use re-use var XHRt = new XMLHttpRequest; // new ajax XHRt.responseType='document'; // ajax2 context and onload() event XHRt.onload= function() { sessionStorage[url]=to.innerHTML= XHRt.response.querySelector(from).innerHTML;}; XHRt.open("GET", url, true); XHRt.send(); return XHRt; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter