Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have recently made a url shortener and I want to make an "Instant Shorten" Bookmark link on my site, like YOURLS can, so you bookmark the link, then go to any webpage, then you click on the bookmark and it automatically shortens the address, adds it to the database and tells you the shortened url in a pop-up.

I'm not sure how to do this, please help me!

Edit: This is the code that YOURLS currently uses to shorten using the bookmark link:

javascript:(function()%7Bvar%20d=document,s=d.createElement('script');window.yourls_callback=function(r)%7Bif(r.short_url)%7Bprompt(r.message,r.short_url);%7Delse%7Balert('An%20error%20occured:%20'+r.message);%7D%7D;s.src='http://nix-pix.co.uk/public/admin/index.php?u='+encodeURIComponent(d.location.href)+'&jsonp=yourls';void(d.body.appendChild(s));%7D)();

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
354 views
Welcome To Ask or Share your Answers For Others

1 Answer

Usually a bookmarklet something like this is used:

javascript:u=encodeURIComponent(location.href);s='http://urlshortener.com/shorten.php?url='+u;window.open(s,'shortened','location=no,width=400,height=300');

That takes the URL of the current page and opens a new window pointing to urlshortener.com/shorten.php?url=[the url to be shortened]. The code used by YOURLS is more complicated, but probably does approximately the same thing. You just need to change the URL that the new window opens to in the code above.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...