2012-03-09 22 views
0

的形式如下:无法获取书签,以POST形式与价值

<form action='localhost/test.php' method='post' target='test'> 
<input type='text' name='add_to_url' value='' /> 
<input type='submit' name='submit' value='Go' /> 
</form> 

而且我不能得到任何东西,甚至接近。

理想情况下,bookmarlet将使用当前网页网址作为add_to_url值,然后提交表单。

任何线索?

回答

0

下面是Javascript代码创建一个表单和发表它。您可以使用它像get2post('http://site.com?a=1&c=2');

下面是一个简单的书签发生器,或谷歌等:http://chris.zarate.org/bookmarkleter

function get2post(u, t) { // u = url, t = target 
    var p = u.split('?')[0]; 
    var q = u.split('?')[1].split('&'); 
    var d = document; 
    var f = d.createElement("form"); 
    f.setAttribute('action', p); 
    f.setAttribute('method', 'POST'); 
    f.setAttribute('target', t || '_parent'); 
    f.style.display = 'none'; 
    for (i = 0; i < q.length; i++) { 
     var e = d.createElement("input"); 
     var param = q[i].split('='); 
     e.name = param[0]; 
     if (param.length >= 2) e.value = decodeURIComponent(param[1]);   
     f.appendChild(e); 
    } 
    d.body.appendChild(f); 
    f.submit(); 
}