Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var XMLHttpRequest = XMLHttpRequest || window.ActiveXObject && function () {
  2.     return new ActiveXObject('Msxml2.XMLHTTP');
  3. };
  4.  
  5. function get_s(url) {
  6.     var xhr = new XMLHttpRequest();
  7.     xhr.open('get', url, false);
  8.     xhr.send(null);
  9.     return xhr.responseText;
  10. }
  11.  
  12.  
  13. window.onload = function () {
  14.     var link = document.getElementById('historyAPI');
  15.     link.addEventListener("click",
  16.             function (e) {
  17.                 e.preventDefault();
  18.                 getContent(link, true);
  19.             }, true
  20.             );
  21. };
  22.  
  23. window.addEventListener("popstate", function (e) {
  24.     getContent(location.pathname, false);
  25. });
  26.  
  27.  
  28.  
  29. function getContent(link, addEntry)
  30. {
  31.     var url = link.href.replace(/^.*?:\/\/.*?(?=\/|$)/, '');
  32.     var result = get_s(url);
  33.     contentHolder.innerHTML = result;
  34.     if (addEntry === true) {
  35.         history.pushState(null, null, link.href);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement