Skip to content

Instantly share code, notes, and snippets.

@xu33
xu33 / new_gist_file
Created August 29, 2013 09:44
Set Cursor Position in Text Area
function setSelectionRange(input, selectionStart, selectionEnd) {
if (input.setSelectionRange) {
input.focus();
input.setSelectionRange(selectionStart, selectionEnd);
}
else if (input.createTextRange) {
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character', selectionEnd);
range.moveStart('character', selectionStart);
@xu33
xu33 / read image from upload
Created September 4, 2013 06:05
read image from upload
function view() {
var f = document.getElementById("file").files[0];
var reader = new FileReader();
reader.onload = (function(evt) { //evt get all value
document.getElementById('div').innerHTML =
"PIC :<img src=" +
evt.target.result + "/>" ;
});
reader.readAsDataURL(f);
}
@xu33
xu33 / html encode and decode
Created September 18, 2013 02:51
html encode and decode
function htmlEscape(str) {
return String(str)
.replace(/&/g, '&amp;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}
function htmlUnescape(value){