I want to post a form and save response html code in a variable using javascript.
here is my code:
<script type="text/javascript">
function submitform()
{
document.forms["myform"].submit();
}
</script>
<form id="myform" action="url" method="post" target="iframe">
<input type="hidden" name="arg" value="value">
<a href="javascript: submitform()">Go</a>
</form>
<iframe name="iframe"></iframe>
if I run this code response will be displayed in iframe. but in some cases after loading iframe page will redirected to source code. I searched many places to stop that redirection to happen but didn't find any way!!.
I just found one way by adding this javascript code:
window.onbeforeunload = function(){
return false;
};
but this way is annoying because it shows a dialog box when redirection and I can't ask users to click on that every time!!
so I chose to find a way to don't load response html code in browser that makes redirection! and instead of that save response in a variable and remove scripts and then print it!!
there is any way to do that?