Sending Text Cross Domain By Bookmarklet

前端 未结 3 579
遥遥无期
遥遥无期 2020-12-15 14:11

I need a user to navigate to a certain page that has a certain div full of useful text. Then click my bookmarklet and send the text in that div back to my server, which is

3条回答
  •  孤街浪徒
    2020-12-15 14:56

    Use javascript to create an iframe. Then add a form to the iframe and submit it. Once the form has been submitted, the onload callback will fire.

    var i=document.createElement('iframe');
    i.setAttribute('name', 'frame-id');
    i.setAttribute('id', 'frame-id');
    i.setAttribute('allowtransparency', 'true');
    i.setAttribute('style', 'border: 0; width: 1px; height: 1px; position: absolute; left: 0; top: 0;');
    i.setAttribute('onload', 'iframeFormSubmitted();');
    
    document.body.appendChild(i);
    
    var html = '' +
    '
    ' + '' + '
    ' + 'var e=encodeURIComponent,w=window,d=document,f=d.getElementById('f');" + "d.getElementById('iframe-form').submit();" + '"; window.frames['frame-id'].document.write(html);

提交回复
热议问题