Note that there are some explanatory texts on larger screens.

plurals
  1. POform POST in iframe without affecting history
    primarykey
    data
    text
    <p>Is it possible to submit a form inside an iframe without affecting the browser's history?</p> <p>I've implemented sending a cross domain POST request. It uses Javascript to create and submit a form inside an iframe. It works, but each request adds an item to the browser's history. </p> <p>Anyone know a way around this? I've tried creating the iframe with both innerHTML and createElement. I've seen no difference so far. </p> <p>PS - I would love to use XMLHtttpRequest ("Ajax"), but it doesn't support sending data across domains. And I would love to use GET instead of post, but I need to send more than 2k of data.</p> <p>Here's one version of my code. I've tried many variations and have searched all over, butI can't seem to find a solution that doesn't affect the browser's history. I believe it's not possible -- can anyone confirm that?</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; function submit(params) { var div = document.createElement('div'); div.innerHTML = '&lt;iframe height="50" width="50"&gt;&lt;/iframe&gt;'; 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() }); } } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Example of using Javascript to POST across domains...&lt;/h1&gt; &lt;input id="button" type="button" value="click to send"&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload