I have a page with an iframe that has no source on page load and just uses hardcoded html like this:
<iframe id="theframe" src="">
<html>
<body>
<form name="theform" action="http://domainB.com/new" method="POST">
<input type="text" />
</form>
</body>
</html>
</iframe>
The form is then submitted in jQuery using
$('#theform').submit();
This causes the source of the iframe to change from nothing (same domain) to domainB.com where the form data is sent and stored.
I then delay 1s to show success msg and then wish to set the frame back to it’s original contents by changing the source back to nothing (same domain) and appending the original form, like this:
$('iframe').attr('src', '');
$('iframe').contents().find('body').empty();
$('iframe').contents().find('body').append('<form name="theform" action="http://domainB.com/new" method="POST"><input type="text" /></form>');
However it’s not working… Is this cross site scripting even though I’m not trying to access the inner content of domainB, I’m just setting the src of the iframe back to domainA??
If so, is there anyway to set the src once it’s been changed to a different domain?
(As I wrote the last sentence I realized I could just delete the iframe and replace it with a new one, I think?, but I’d still like to know if changing the source is considered cross site and thats why it’s not working?)
This just returns
trueorfalse.Maybe you’re looking for this: