2012-03-09 24 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(); 
}