话说离上一篇日志的发表时间已有漫长的四个多月,实在是对不住读者。客观原因找一下,但是还是要实事求是:一是因为工作实在是太忙太累,无暇顾及;二是BLOG系统太慢,从前到后都需要大概,在开忙之前想修改BLOG系统来着,结果改了一点点就开始忙得不可开交了,于是也中止了。

春节休息了几天,今天上班第一天,最近混twitter混得比较多,经常要压缩URL,以前做了个书签http://is.gd/压缩,后来发现了全球最短的URL——http://to./,于是决定换API压缩。以前的API可以用GET方式提交数据压缩,但是这个却需要用POST方式提交,因此需要在弹出窗口的同时用POST提交数据。实现起来很简单:在弹出窗口中生成一个表单,把value写到对应的字段中,打开弹出窗口后再用js提交表单即可。

代码如下:

javascript: void(function() {
	var p = 'http://to./',
	u = location.href,
	x = function() {
		s = '<form name="f" id="f" action="' + p + '" method="post"><input type="text" name="url" size="9" maxlength="999" value="' + u + '" /></form><script type="text/javascript">document.f.submit();</script>';
		w = window.open('', 'W', 'toolbar=0,resizable=1,scrollbars=no,status=1,width=320,height=240');
		w.document.write(s);
		if (!w) location.href = p + '?url=' + encodeURIComponent(location.href);
	};
	if (/Firefox/.test(navigator.userAgent)) {
		setTimeout(x, 0)
	} else {
		x()
	}
})()

使用方法很简单:

1.先把当前页面加入书签,然后修改书签的属性,更改链接名称,然后更改链接地址为:

javascript:void(function(){var p='http://to./',u=location.href,x=function(){s='<form name="f" id="f" action="'+p+'" method="post"><input type="text" name="url" size="9" maxlength="999" value="'+u+'" /></form><script type="text/javascript">document.f.submit();</script>';w=window.open('','W','toolbar=0,resizable=1,scrollbars=no,status=1,width=320,height=240');w.document.write(s);if(!w)location.href=p+'?url='+encodeURIComponent(location.href);};if(/Firefox/.test(navigator.userAgent)){setTimeout(x, 0)}else{x()}})()

2.打开你要压缩URL的页面,在书签栏点击这个书签,按下Ctrl + C复制就可以了,方便吧?

3 Comments

Leave a Reply to 密陀僧 Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.