最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - submit form from iframe and close it after submit and show a hidden div - Stack Overflow

programmeradmin5浏览0评论

this is what I have

    <html>
    <head>
    </head>
    <body>
    <iframe id="myiframe">
    <form id= "myform" action="submit.php" method="POST">
    <input type="submit">
    </form></iframe>
    <div id="hiddendiv" style="display:none">
    some text
    </div>
    </body></html>

and this is what I want to end up with after the form in the iframe is submitted (ether by enter or just clicking the button submit, I do not care because the form only has 1 field)

    <html>
    <head>
    </head>
    <body>
    //I want this iframe to bee display:none or to be deleted
    /*<iframe id="myiframe">
    <form id= "myform" action="submit.php" method="POST">
    <input type="submit">
    </form></iframe>*/
    //and this div to be showed
    <div id="hiddendiv" style="display:">
    some text
    </div>
    </body></html>

can anyone please help, thanks

i have the answare but I have to wait for 8 h to post is so I edited the initial question, you can pot is if you want so I can validate it as a answare

got it

<html>
<head>
</head>
<body>
<script>

function closeIframe() {
var iframe = document.getElementById('myiframe');
iframe.parentNode.removeChild(iframe);
document.getElementById("hiddendiv").style.display="";
}

</script>
<iframe id="myiframe">
<form id= "myform" action="submit.php" method="POST">
<input type="submit">
</form></iframe>
<div id="hiddendiv" style="display:none">
some text
</div>
</body></html>

and in the submit.php the return is this

echo '<script type="text/javascript">';
echo 'parent.closeIframe()';
echo '</script>';

this is what I have

    <html>
    <head>
    </head>
    <body>
    <iframe id="myiframe">
    <form id= "myform" action="submit.php" method="POST">
    <input type="submit">
    </form></iframe>
    <div id="hiddendiv" style="display:none">
    some text
    </div>
    </body></html>

and this is what I want to end up with after the form in the iframe is submitted (ether by enter or just clicking the button submit, I do not care because the form only has 1 field)

    <html>
    <head>
    </head>
    <body>
    //I want this iframe to bee display:none or to be deleted
    /*<iframe id="myiframe">
    <form id= "myform" action="submit.php" method="POST">
    <input type="submit">
    </form></iframe>*/
    //and this div to be showed
    <div id="hiddendiv" style="display:">
    some text
    </div>
    </body></html>

can anyone please help, thanks

i have the answare but I have to wait for 8 h to post is so I edited the initial question, you can pot is if you want so I can validate it as a answare

got it

<html>
<head>
</head>
<body>
<script>

function closeIframe() {
var iframe = document.getElementById('myiframe');
iframe.parentNode.removeChild(iframe);
document.getElementById("hiddendiv").style.display="";
}

</script>
<iframe id="myiframe">
<form id= "myform" action="submit.php" method="POST">
<input type="submit">
</form></iframe>
<div id="hiddendiv" style="display:none">
some text
</div>
</body></html>

and in the submit.php the return is this

echo '<script type="text/javascript">';
echo 'parent.closeIframe()';
echo '</script>';
Share edited Feb 1, 2013 at 14:29 user2031113 asked Feb 1, 2013 at 11:48 user2031113user2031113 932 gold badges3 silver badges7 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 1

If from same domain, add this in the submit.php and extract the form to put in the iframe You need

<iframe src="form.html"></iframe>

DEMO

<script>
top.document.getElementById("myiframe").style.display="none";        
top.document.getElementById("hiddendiv").style.display="block";
</script>
<html>
<head>
</head>
<body>
<script>

function closeIframe() {
var iframe = document.getElementById('myiframe');
iframe.parentNode.removeChild(iframe);
document.getElementById("hiddendiv").style.display="";
}

</script>
<iframe id="myiframe">
<form id= "myform" action="submit.php" method="POST">
<input type="submit">
</form></iframe>
<div id="hiddendiv" style="display:none">
some text
</div>
</body></html>

and in the submit.php the return is this

echo '<script type="text/javascript">';
echo 'parent.closeIframe()';
echo '</script>';
发布评论

评论列表(0)

  1. 暂无评论