Last active
August 29, 2015 14:08
-
-
Save matdombrock/e3a22e58f0a97aecb606 to your computer and use it in GitHub Desktop.
Generates a page with a link to a another random bitly page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="result">loading...</div> | |
<p id="reload">CLICK HERE TO GENERATE A NEW LINK</p> | |
<script> | |
function randomString(len, charSet) { | |
charSet = charSet || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | |
var randomString = ''; | |
for (var i = 0; i < len; i++) { | |
var randomPoz = Math.floor(Math.random() * charSet.length); | |
randomString += charSet.substring(randomPoz,randomPoz+1); | |
} | |
return randomString; | |
} | |
function randomIntFromInterval(min,max) { return Math.floor(Math.random()*(max-min+1)+min); } | |
var randomValue = randomString(randomIntFromInterval(4,6)); | |
$("#result").html("<a href='http://www.bit.ly/"+randomValue+"' target='_blank'>bit.ly/"+randomValue+"</a>"); | |
$( "#reload" ).click(function() { | |
window.location.reload(true); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment