4

有用なテキストでいっぱいの特定の div を持つ特定のページに移動するユーザーが必要です。次に、ブックマークレットをクリックして、その div 内のテキストを現在のドメインとは異なるサーバーに送信します。ブックマークレットのクリックで jQuery を正常に挿入し、テキストを選択しました。次に、そのテキストをクロスドメインでサーバーに送信する方法を見つける必要があります。jQuery で JSONP を試しましたが、URL に対してテキストが長すぎます。私の 2 番目のアイデアは、新しいウィンドウを開いてドメインからページをロードし、選択したテキストを新しいウィンドウに何らかの方法で挿入することでした。その後、ユーザーは送信をクリックして、そのデータをサーバーに POST できます。これは、JavaScript クロスサイトの理由で機能しませんでした。誰でもこれを経験したり、これを行うためのアイデアを持っていますか? ありがとう。

4

3 に答える 3

5

(DOM を使用して) フォームを生成し、データを POST します (iframe をターゲットにしたい場合がありますが、それは起動して忘れてしまいます)。

于 2010-02-03T21:01:33.257 に答える
4

テキストをリモートサーバーに投稿する例を次に示します。また、iframe があるページを変更して成功のようなことを言いたい場合は、リモート サーバーで JavaScript を印刷できます。または、終了したことを示すポップアップ。リモートサーバーでは、これを印刷してポップアップを作成できます。

<script> parent.document.getElementById('postmessage').style.display='block'; parent.alert('Successfully posted');</script>

情報を発信したいWebページに、こんな感じでフォームとiframeを作ります。

<span id="postmessage" style="display:none">Success Message</span>
<form action="http://www.remoteserver.com/upload_test.php" method="post" target="post_to_iframe">
  <input type="hidden" value="the text to send to remote server" />
  <input type="submit" value="Submit" />
</form>

<!-- When you submit the form it will submit to this iFrame without refreshing the page and it will make the popup and display the message. -->
<iframe name="post_to_iframe" style="width: 600px; height: 500px;"></iframe>
于 2012-03-16T19:47:29.267 に答える
3

javascript を使用して iframe を作成します。次に、iframe にフォームを追加して送信します。フォームが送信されると、onload コールバックが発生します。

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 = '<html><body>' +
'<form action="/post_url" method="post" id="iframe-form" accept-charset="utf-8">' +
'<input type="hidden" name="id" value="' + your_text + '"/>' +
'</form>' +
'<scr'+"ipt>var e=encodeURIComponent,w=window,d=document,f=d.getElementById('f');" +
"d.getElementById('iframe-form').submit();" +
'</scr'+"ipt></body></html>";

window.frames['frame-id'].document.write(html);
于 2012-03-31T00:56:28.017 に答える