<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>URL Encoding/Decoding</title>
  <style>
    .container {
      max-width: 600px;
      margin-top: 2rem;
      padding: 2rem;
      background-color: #fff;
      border-radius: 5px;
      box-shadow: 0 0 5px rgba(0,0,0,0.1);
    }

    .result-text {
      color: #444;
      background-color: #f2f2f2;
    }
  </style>
</head>
<body>
  <div class="container">
    <h1 class="text-center mb-4">URL Encoding/Decoding</h1>
    <div class="form-group">
      <label for="input-textarea">Enter URL:</label>
      <textarea id="input-textarea" class="form-control" placeholder="Enter URL" rows="5"></textarea>
    </div>
    <div class="form-group">
      <button id="encode-button" class="btn btn-primary btn-block" onclick="encode()">Encode</button>
      <button id="decode-button" class="btn btn-secondary btn-block" onclick="decode()">Decode</button>
    </div>
    <div class="form-group">
      <label for="output-textarea" class="font-weight-bold">Result:</label>
      <textarea id="output-textarea" class="form-control result-text" rows="5" readonly></textarea>
    </div>
    <div class="form-group">
      <button id="copy-button" class="btn btn-secondary btn-block" onclick="copyResult()">Copy</button>
    </div>
  </div>


  <script>
    function encode() {
      const input = document.getElementById("input-textarea").value;
      const output = encodeURIComponent(input);
      document.getElementById("output-textarea").value = output;
    }

    function decode() {
      const input = document.getElementById("input-textarea").value;
      const output = decodeURIComponent(input);
      document.getElementById("output-textarea").value = output;
    }

    function copyResult() {
      const outputTextarea = document.getElementById("output-textarea");
      outputTextarea.select();
      outputTextarea.setSelectionRange(0, 99999); // For mobile devices
      document.execCommand("copy");
      alert("Result copied to clipboard.");
    }
  </script>
</body>
</html>

+ Recent posts