Javascript bookmarklet to take info from one page and submit it to form on another page

前端 未结 1 1866
南笙
南笙 2021-01-21 16:33

Now that I discovered here that I can\'t write JavaScript within one page to enter form data on another external page, I\'d like to do this with a browser-based bookmarklet inst

相关标签:
1条回答
  • 2021-01-21 16:54

    That's because the bookmarklet runs within the sandbox (the environment) of the current web page. Since you're not allowed to access (the DOM of) another page which doesn't have the same protocol, domain name and port, you're not able to access the document property of newWindow when protocols, domains and ports don't match. BTW, the same is true for accessing iframes on a page.

    As you're talking about an “external form”, I guess you don't stay on the same domain. The other examples retrieve or manipulate data on the current page (at that moment) and won't error out.

    Also see Same origin policy.

    Update: About the Delicious (et al.) bookmarklet: its code actually reads:

    (function () {
        f = 'http://delicious.com/save?url=' + encodeURIComponent(window.location.href) + '&title=' + encodeURIComponent(document.title) + '&v=5&';
        a = function () {
            if (!window.open(f + 'noui=1&jump=doclose', 'deliciousuiv5', 'location=yes,links=no,scrollbars=no,toolbar=no,width=550,height=550'))
                location.href = f + 'jump=yes'
        };
        if (/Firefox/.test(navigator.userAgent)) {
            setTimeout(a, 0)
        } else {
            a()
        }
    })()
    

    So, yes, the parameters are only transferred using a GET request.

    0 讨论(0)
提交回复
热议问题