Created
July 30, 2012 22:42
-
-
Save monsur/3211294 to your computer and use it in GitHub Desktop.
Generate a table comparing the differences between the escape, encodeURI, and encodeURIComponent functions
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 createRow(c, tr) { | |
var td = document.createElement('td'); | |
td.align = 'center'; | |
td.innerHTML = c; | |
if (c[0] !== '%') { | |
td.style.backgroundColor = '#ffc'; | |
} | |
tr.appendChild(td); | |
} | |
function createTable(tableId) { | |
for (var i = 0; i < 128; i++) { | |
var c = String.fromCharCode(i); | |
var c1 = escape(c); | |
var c2 = encodeURI(c); | |
var c3 = encodeURIComponent(c); | |
if ((c1 === c2) && (c2 === c3)) { | |
continue; | |
} | |
var tr = document.createElement('tr'); | |
var td = document.createElement('td'); | |
td.align = 'center'; | |
td.innerHTML = c; | |
tr.appendChild(td); | |
createRow(c1, tr); | |
createRow(c2, tr); | |
createRow(c3, tr); | |
document.getElementById(tableId).appendChild(tr); | |
} | |
} | |
createTable('results'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment