无法将书签添加到具有值的 POST 表单

Can't get bookmarklet to POST form with value

本文关键字:POST 表单 书签 添加      更新时间:2023-09-26

表单如下所示:

 <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 将使用当前网页 URL 作为add_to_url值,然后提交表单。

有线索吗?

要获取当前页面的网址,您需要使用 location.href Javascript 属性。

要开始开发书签,您可以通过以下链接:http://www.bookmarklets.com/tools/categor.htmlhttp://betterexplained.com/articles/how-to-make-a-bookmarklet-for-your-web-application/

此外,您可以在搜索书签上搜索书签 Javascript 代码

下面是用于创建表单并发布它的 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();
}