Every single component of the Web handles strings, and especially Unicode characters encoding, differently.
This document aims to gather all the important information about character encodings on the Web.
Here's a list of tiny functions whose goal is to convert any Unicode string in 28 different formats used on the Web, and do the reverse operation.
An online converter using those functions can be found here: http://xem.github.io/escape
Please contribute in the comments (or by pull request) if you have a feature idea or a code-golf improvement to make or a bug to solve.
NB: to be as short as possible, all those functions assume a valid input and convert all chars (including ASCII chars and non-ASCII chars that don't really need to be converted in some cases).
<html ondrop="f(event);return!1"ondragover=return!1> | |
<script> | |
f=function(e){ | |
r=new FileReader; | |
d=e.dataTransfer.files; | |
for(i=0;i<d.length;i++){ | |
r.readAsArrayBuffer(d[i]); | |
} | |
r.onload=function(a){ | |
console.log(r.result); // wat? If I drop multiple files, there's only one ArrayBuffer there (on FF) and it doesn't work at all (on chrome) |
<html ondrop="f(event);return!1"ondragover=return!1> | |
<script> | |
f=function(e){ | |
d=e.dataTransfer.files; | |
for(i=0;i<d.length;i++){ | |
with(new FileReader){ | |
readAsArrayBuffer(d[i]); | |
onload=function(){console.log(new Uint8Array(result))}; | |
} | |
} |
...or any text you often need to write in form fields.
Works with inputs, textareas and contenteditable elements.
Doesn't work on HTTPS on Firefox 23+.
javascript:(function(d){d=document.activeElement;if(d.tagName=="INPUT"||d.tagName=="TEXTAREA"||d.contentEditable=="true"){d.value=d.innerHTML="my_email@my_email_provider.com"}})()
/* Y U NO ? */ | |
body { background: #13579B; } | |
.outer1 { width: 100px; height: 100px; margin: 100px auto; } | |
.inner1 { width: 100%; height: 100%; text-align: center; background: #FEDCBA; transition: all 1s ease; } | |
.outer1:hover { position: absolute; top: 0; left: 0; } | |
.outer2 { width: 100px; height: 100px; position: relative; margin: 100px auto; } | |
.outer2:hover { position: static; } |
/* zoom */ | |
* { margin: 0; padding: 0; } | |
.containerTable { width: 200px; height: 100px; margin: 100px 0 0 300px; background: #987654; } | |
.containerTd { width: 100px; height: 100px; vertical-align:top; } | |
div { text-align: center; width: 100px; height: 100px; background: #ECA864; border: 1px solid black; transition: all 1s ease; position: absolute; } | |
div.zoom { width: 1024px; height: 700px; margin-left: -300px; margin-top: -100px; position: absolute; } | |
/* Y U NO ? */ | |
body { background: #13579B; } | |
.outer1 { width: 100px; height: 100px; margin: 100px auto; } | |
.inner1 { width: 100%; height: 100%; text-align: center; background: #FEDCBA; transition: all 1s ease; } | |
.outer1:hover { position: absolute; top: 0; left: 0; } | |
.outer2 { width: 100px; height: 100px; position: relative; margin: 100px auto; } | |
.outer2:hover { position: static; } |