for (var i in location) {
  if (typeof location[i] === "string") {
    console.log(i + ' = "' + location[i] + '"');
  }
}
      href = "http://search.phpied.com:8080/search?
      q=java&what=script#results"
      hash = "#results"
      host = "search.phpied.com:8080"
      hostname = "search.phpied.com"
      pathname = "/search"
      port = <<8080>>
      protocol = <<http:>>
      search = "?q=java&what=script"

---

<!DOCTYPE html>
<html>
  <head>
    <title>Moja strona</title>
  </head>
  <body>
    <p class="opener">pierwszy akapit</p>
    <p><em>drugi</em> akapit</p>
    <p id="closer">ostatni</p>
    <!-- koniec -->
  </body>
</html>

---

function toggle(){
  var st = document.querySelectorAll('button')[2].style;
  st.visibility = (st.visibility === 'hidden') 
    ? 'visible'
    : 'hidden';
}

---

// utwórz element P
var myp = document.createElement('p');
// utwórz węzeł tekstowy i dodaj do P
var myt = document.createTextNode('jeszcze jeden akapit ')
myp.appendChild(myt);
// utwórz element STRONG i dodaj do niego węzeł tekstowy
var str = document.createElement('strong');
str.appendChild(document.createTextNode('pogrubiony'));
// dodaj STRONG do P
myp.appendChild(str);
// dodaj P do BODY
document.body.appendChild(myp);

---

<div id="my-div">kliknij</div>
<script>
  var myelement = document.getElementById('my-div');
  myelement.onclick = function() {
    alert('Ałka!');
    alert('Drugie ałka!');
  }
</script>

---

// wszystkie linki
var all_links = document.getElementsByTagName('a');
for (var i = 0; i < all_links.length; i++) { // pętla przez wszystkie linki
  all_links[i].addEventListener(
    'click', // typ zdarzenia
    function(e){ // procedura obsługi zdarzenia
      if (!confirm('Czy na pewno chcesz przejść na inną stronę?')){
        e.preventDefault();
      }
    },
    false // nie stosuj przechwytywania
  );
}

---

function callback(evt) {
  // przygotowanie
  evt = evt || window.event;
  var target = evt.target || evt.srcElement;

  // wywołanie zwrotne
  console.log(target.nodeName);
}

// rozpocznij nasłuchiwanie kliknięć
if (document.addEventListener){ // Nowoczesne przeglądarki
  document.addEventListener('click', callback, false);
} else if (document.attachEvent){ // Stara wersja IE
  document.attachEvent('onclick', callback);
} else {
  document.onclick = callback; //zamierzchłe czasy
}

---

function myCallback() {
  if (xhr.readyState < 4) {
    return; // jeszcze niegotowe
  }
  if (xhr.status !== 200) {
    alert('Błąd!'); // kod statusu żądania HTTP jest inny niż OK
    return;
  }
  // wszystko w porządku, zatem do dzieła!
  alert(xhr.responseText);
}

---

var ids = ['MSXML2.XMLHTTP.3.0', 
           'MSXML2.XMLHTTP', 
           'Microsoft.XMLHTTP'];
var xhr;
if (XMLHttpRequest) {
  xhr = new XMLHttpRequest();
} else {
  // Spróbuj znaleźć obiekt ActiveX i użyć go
  for (var i = 0; i < ids.length; i++) {
    try {
      xhr = new ActiveXObject(ids[i]);
      break;
    } catch (e){}
  }
}

---

var xhr = new XMLHttpRequest();

xhr.onreadystatechange = (function(myxhr){
  return function(){
    myCallback(myxhr);
  }
}(xhr));

xhr.open('GET', 'plik.txt', true);
xhr.send('');

---

function request(url, callback) {
  var xhr = new XMLHttpRequest();
  xhr.onreadystatechange = (function(myxhr){
    return function(){
      if (myxhr.readyState === 4 && myxhr.status === 200) {
        callback(myxhr);
      }
    };
  }(xhr));
  xhr.open('GET', url, true);
  xhr.send('');
}

---

request(
  'http://www.phpied.com/files/jsoop/content.txt',
  function(o){
    document.getElementById('text').innerHTML = o.responseText;
  }
);
request(
  'http://www.phpied.com/files/jsoop/content.html',
  function(o){
    document.getElementById('html').innerHTML = o.responseText;
  }
);
request(
  'http://www.phpied.com/files/jsoop/content.xml',
  function(o){
    document.getElementById('xml').innerHTML =     
      o.responseXML
       .getElementsByTagName('root')[0]
       .firstChild
       .nodeValue;
  }
);

---

