问题描述
我最近制作了一个网址缩短器,我想在我的网站上制作一个即时缩短"书签链接,就像 YOURLS 一样可以,因此您可以为链接添加书签,然后转到任何网页,然后单击书签并它会自动缩短地址,将其添加到数据库中并在弹出窗口中告诉您缩短的网址.
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!
这是 YOURLS 当前使用书签链接缩短的代码:
This is the code that YOURLS currently uses to shorten using the bookmark link:
javascript:(function()%7Bvar%20d=document,s=d.createElement('script');window.youurls_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=youurls';void(d.body.appendChild(s));%7D)();
推荐答案
通常使用这样的书签:
javascript:u=encodeURIComponent(location.href);s='http://urlshortener.com/shorten.php?url='+u;window.open(s,'shortened','location=no,width=400,height=300');
这会获取当前页面的 URL 并打开一个指向 urlshortener.com/shorten.php?url=[要缩短的 url] 的新窗口.YOURLS 使用的代码更复杂,但可能做的事情大致相同.您只需要在上面的代码中更改新窗口打开的 URL.
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.
这篇关于如何为网址缩短器制作即时缩短链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!