gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
html css js url shortener share "#/seed="
- User
html css js url shortener share "#/seed="
- Assistant
html css js url shortener share "#/seed="
If you want to create a simple URL shortener-like feature using HTML, CSS, and JavaScript that encodes some data into the URL fragment (hash) with a pattern like #/seed=, and also allows sharing the shortened URL, here is a basic example.
#/seed=ENCODED_STRING<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Simple URL Shortener with #/seed=</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 2rem;
}
input[type="text"] {
width: 80%;
padding: 8px;
margin-bottom: 1rem;
}
button {
padding: 8px 16px;
margin-left: 0.5rem;
}
#output {
margin-top: 1rem;
font-size: 1rem;
word-break: break-all;
}
#decoded {
margin-top: 1rem;
font-weight: bold;
}
</style>
</head>
<body>
<h1>Simple URL "Shortener" with #/seed=</h1>
<input type="text" id="inputURL" placeholder="Enter URL or text to shorten" />
<button id="shortenBtn">Shorten</button>
<button id="shareBtn" disabled>Copy Shortened URL</button>
<div id="output"></div>
<div id="decoded"></div>
<script>
// Base64 encode/decode helpers
function encodeSeed(str) {
return btoa(unescape(encodeURIComponent(str)));
}
function decodeSeed(str) {
return decodeURIComponent(escape(atob(str)));
}
// Update URL hash with encoded seed
function updateHash(encoded) {
location.hash = `/seed=${encoded}`;
}
// Read hash and decode seed
function readHash() {
const hash = location.hash;
if (hash.startsWith('#/seed=')) {
const seed = hash.slice(7);
try {
return decodeSeed(seed);
} catch (e) {
return null;
}
}
return null;
}
// Elements
const inputURL = document.getElementById('inputURL');
const shortenBtn = document.getElementById('shortenBtn');
const shareBtn = document.getElementById('shareBtn');
const output = document.getElementById('output');
const decoded = document.getElementById('decoded');
// When clicking shorten, encode and update hash
shortenBtn.addEventListener('click', () => {
const val = inputURL.value.trim();
if (!val) return alert('Please input some text or URL.');
const encoded = encodeSeed(val);
updateHash(encoded);
const shortURL = `${location.origin}${location.pathname}#/seed=${encoded}`;
output.textContent = `Shortened URL: ${shortURL}`;
shareBtn.disabled = false;
decoded.textContent = '';
});
// When clicking share, copy shortened URL
shareBtn.addEventListener('click', () => {
const shortURL = `${location.origin}${location.pathname}${location.hash}`;
navigator.clipboard.writeText(shortURL).then(() => {
alert('Shortened URL copied to clipboard!');
}, () => {
alert('Failed to copy URL. Please copy manually:\n' + shortURL);
});
});
// On page load or hash change, decode and show original
function handleHashChange() {
const original = readHash();
if (original) {
decoded.textContent = `Decoded original: ${original}`;
shareBtn.disabled = false;
output.textContent = '';
inputURL.value = '';
} else {
decoded.textContent = '';
shareBtn.disabled = true;
}
}
window.addEventListener('hashchange', handleHashChange);
window.addEventListener('load', handleHashChange);
</script>
</body>
</html>
#/seed=....If you want something more advanced (like generating random short codes mapping on the server side), that would require a backend.
Let me know if you want enhancements or how to persist on the server!
Not yet included in a published release.