Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.06 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Using HTML5 localstorage to update some text without document.write
  2. var cardID = 1;
  3. var cardValues = new Array();
  4. var name = "Shifting Sliver";
  5. var cost = "3U";
  6. var text = "Sliver cannot be blocked except by slivers.";
  7. var power = "2";
  8. var toughness = "2";
  9.  
  10. cardValues.push(name);
  11. cardValues.push(cost);
  12. cardValues.push(text);
  13. cardValues.push(power);
  14. cardValues.push(toughness);
  15.  
  16. localStorage.setItem(cardID, cardValues.join(";"));
  17.  
  18.  
  19. var cardKey = localStorage.key(0);
  20. var getCardValues = localStorage.getItem(cardKey);
  21. values = getCardValues.split(";");
  22. var name = values[0];
  23. var cost = values[1];
  24. var text = values[2];
  25. var power = values[3];
  26. var toughness = values[4];
  27.  
  28. function writeCard()
  29. {
  30.     document.write('Card Name: ' + name + '<br />');
  31.     document.write('Card Cost: ' + cost + '<br />');
  32.     document.write('Card Text: ' + text + '<br />');
  33.     document.write('Card Power: ' + power + '<br />');
  34.     document.write('Card Toughness: ' + toughness);
  35. }
  36.        
  37. <div class="card">
  38.     <div class="info"><script type='text/javascript'> writeCard(); </script></div>
  39. </div>