본문 바로가기

스크립트/Keyboard관련

decode encode javascript 기능

function encode() {
 var obj = document.getElementById('dencoder');
 var unencoded = obj.value;
 obj.value = encodeURIComponent(unencoded);
}
function decode() {
 var obj = document.getElementById('dencoder');
 var encoded = obj.value;
 obj.value = decodeURIComponent(encoded.replace(/\+/g,  " "));
}
</script>
</head>
<body>
<form onsubmit="return false;">
<h1>URL Decoder/Encoder</h1>
<textarea cols="80" rows="5" id="dencoder"></textarea>
<div>
<input type="button" onclick="decode()" value="Decode">
<input type="button" onclick="encode()" value="Encode">
</div>
</form>