网络编程
位置:首页>> 网络编程>> JavaScript>> 在弹出窗口用POST提交数据

在弹出窗口用POST提交数据

作者:Fdream 来源:Fdream博客 发布时间:2010-02-24 09:39:00 

标签:post,弹出窗口,提交,get

春节休息了几天,今天上班第一天,最近混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复制就可以了,方便吧?

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com