Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- // Pure JS URL shortener, see http://www.lanoiadimuu.it/2014/12/the-cheapest-js-url-shortener-ever/
- // Function declaration
- function shorturl_redirect() {
- // This JSON array contains all the shorturl/url pairs
- var urls =[ { "shorturl":"?lndm" , "redirect":"http://www.lanoiadimuu.it" },
- { "shorturl":"?example" , "redirect":"http://www.example.com" },
- { "shorturl":"?twitter" , "redirect":"http://twitter.com/lanoiadimuu" },
- // Get the url parameter
- var shorturl = location.search;
- // If there's no url parameter stop script execution
- if(!shorturl || 0 === shorturl.length) { return; }
- // Now the function will look though urls array and if a valid shorturl is found it will redirect the browser to the longer url
- for(i = 0; i < urls.length; i++) {
- if(shorturl == urls[i].shorturl) {
- window.location.replace(urls[i].redirect)
- break;
- }
- }
- }
- // Function call
- shorturl_redirect();
- // -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement