2023-08-07T16:52:02.png
2023-08-07T16:52:14.png

常规

<!DOCTYPE html>
<html>
<head>
    <title>链接Base64编码示例</title>
</head>
<body>
    <input type="text" id="urlInput" placeholder="输入链接">
    <button onclick="encodeURL()">编码链接</button>
    <p>编码结果:</p>
    <textarea id="encodedOutput" rows="5" readonly></textarea>

    <script>
        function encodeURL() {
            var urlInput = document.getElementById("urlInput").value;
            var encodedOutput = document.getElementById("encodedOutput");

            var base64EncodedURL = btoa(urlInput);
            encodedOutput.value = base64EncodedURL;
        }
    </script>
</body>
</html>

链接含中文

<!DOCTYPE html>
<html>
<head>
    <title>链接Base64编码及中文编码示例</title>
</head>
<body>
    <input type="text" id="urlInput" placeholder="输入链接">
    <button onclick="encodeURL()">编码链接</button>
    <p>编码结果:</p>
    <textarea id="encodedOutput" rows="5" readonly></textarea>

    <script>
        function encodeURL() {
            var urlInput = document.getElementById("urlInput").value;
            var encodedOutput = document.getElementById("encodedOutput");

            var encodedURL = encodeURIComponent(urlInput);
            var encodedURLWithSpecialChars = encodedURL.replace(/%3A/g, ":").replace(/%2F/g, "/");
            var base64EncodedURL = btoa(encodedURLWithSpecialChars);
            encodedOutput.value = base64EncodedURL;
        }
    </script>
</body>
</html>