ブラウザの履歴に影響を与えることなく、iframe内でフォームを送信することは可能ですか?
クロスドメインPOSTリクエストの送信を実装しました。Javascriptを使用して、iframe内にフォームを作成して送信します。動作しますが、リクエストごとにブラウザの履歴にアイテムが追加されます。
誰かがこれを回避する方法を知っていますか?私はinnerHTMLとcreateElementの両方でiframeを作成してみました。今のところ違いは見ていません。
PS-XMLHtttpRequest( "Ajax")を使用したいのですが、ドメイン間でのデータ送信はサポートされていません。また、投稿の代わりにGETを使用したいのですが、2kを超えるデータを送信する必要があります。
これが私のコードの1つのバージョンです。私は多くのバリエーションを試し、すべてを検索しましたが、ブラウザの履歴に影響を与えない解決策を見つけることができないようです。それは不可能だと思います-誰かがそれを確認できますか?
<html>
<head>
<script type="text/javascript">
function submit(params) {
var div = document.createElement('div');
div.innerHTML = '<iframe height="50" width="50"></iframe>';
document.body.appendChild(div);
var iframe = div.firstChild;
var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
iframeDocument.open();
iframeDocument.close();
var form = iframeDocument.createElement('form');
iframeDocument.body.appendChild(form);
form.setAttribute('action', 'http://some-other-domain.com/submit-here');
form.setAttribute('method', 'POST');
for (param in params) {
var field = iframeDocument.createElement('input');
field.setAttribute('type', 'hidden');
field.setAttribute('name', param);
field.setAttribute('value', params[param]);
form.appendChild(field);
}
form.submit();
}
window.onload = function() {
document.getElementById('button').onclick = function() {
submit({
'x' : 'Some Value',
'y' : 'Another Value',
'z' : new Date().getTime()
});
}
}
</script>
</head>
<body>
<h1>Example of using Javascript to POST across domains...</h1>
<input id="button" type="button" value="click to send">
</body>
</html>