Skip to content

Instantly share code, notes, and snippets.

@santosh
Created January 11, 2013 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save santosh/4508179 to your computer and use it in GitHub Desktop.
Save santosh/4508179 to your computer and use it in GitHub Desktop.
JavaScript: URL dencoder is an URL encoder and decoder. The core is entirely written in JavaScript.
<!DOCTYPE html>
<html dir="ltr" lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width">
<title>URL Decoder/Encoder</title>
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
</head>
<body>
<form onsubmit="return false;">
<h1>URL Decoder/Encoder</h1>
<textarea placeholder="Write your stuffs here" cols="80" rows="20" id="dencoder"></textarea>
<div>
<input type="button" onclick="decode()" value="Decode">
<input type="button" onclick="encode()" value="Encode">
</div>
</form>
<script type="text/javascript" src="dencoder.js"></script>
</body>
</html>
// define the id of the textarea carefully
function encode() {
var obj = document.getElementById('dencoder');
var unencoded = obj.value;
obj.value = encodeURIComponent(unencoded);
}
// define the id of the textarea carefully
function decode() {
var obj = document.getElementById('dencoder');
var encoded = obj.value;
obj.value = decodeURIComponent(encoded.replace(/\+/g, " "));
}
form {
margin: 0;
}
h1 {
font-family: Arial, sans-serif;
line-height: 0.85em;
margin-bottom: 0.33em;
padding-bottom: 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment