admin管理员组文章数量:1406453
I've probably overplicated things, but being relatively new to the whole process, I didn't know what else to do. I have an order form inside an iframe, which is inside a jQuery UI dialog lightbox. It all works, except for one problem: when the form is submitted and it redirects to either the thank-you or error page, it's scrolled at the bottom.
I've tried using onload="window.parent.scroll(0,0);"
in the tags of the thank-you and error pages, but that didn't do anything.
Also tried:
<script type="text/javascript">
$("#orderform").onsubmit(function() {
$("#dialog").window.scrollTo(0,0);
alert('triggered');
});
</script>
I've placed the script everywhere I could think of, the index page, inside the for the dialog, inside the iframe, in the form's page, never even got an alert.
The test server currently hosting the site is /
I've probably overplicated things, but being relatively new to the whole process, I didn't know what else to do. I have an order form inside an iframe, which is inside a jQuery UI dialog lightbox. It all works, except for one problem: when the form is submitted and it redirects to either the thank-you or error page, it's scrolled at the bottom.
I've tried using onload="window.parent.scroll(0,0);"
in the tags of the thank-you and error pages, but that didn't do anything.
Also tried:
<script type="text/javascript">
$("#orderform").onsubmit(function() {
$("#dialog").window.scrollTo(0,0);
alert('triggered');
});
</script>
I've placed the script everywhere I could think of, the index page, inside the for the dialog, inside the iframe, in the form's page, never even got an alert.
The test server currently hosting the site is http://kinnill./dev/bluehydrangea/
Share Improve this question edited Nov 23, 2011 at 23:25 Heinrich Ulbricht 10.4k5 gold badges59 silver badges94 bronze badges asked Nov 23, 2011 at 16:26 MWhitmoreMWhitmore 933 silver badges13 bronze badges1 Answer
Reset to default 6Not sure which page you want to scroll to the top. The dialog box, the page the dialog box is on, or the page that is in the iframe?
After looking at your code I believe this is the one you are after:
If the dialog has a scrollable element that is already scrolled down after the iframe changes, then you will want to target whatever element has "overflow: auto". If that element is #dialog then do this on the iframe page the form is in (which in your case looks to be form.php):
<script type="text/javascript">
$(function(){
$("#orderform").submit(function() {//note: in jquery the onsubmit event is called "submit"
$('#dialog', window.parent.document).scrollTop(0);//target #dialog from the parent window
alert('triggered');
});
});
</script>
Other possible solutions for reference for others:
If its the page the dialog is on then do the following:
If the form is in the iframe then the code needs to be in the iframe. You will then need to modify the code to target the parent window.
This should be what you are looking for:
<script type="text/javascript">
$("#orderform").submit(function() {
$(window.parent).scrollTop(0);
alert('triggered');
});
</script>
If the page you want to scroll is the thank you page or the error page then put the following on the thank you and error pages: (you will need jquery on the thank you and error pages)
<script type="text/javascript">
$(function(){
$(window).scrollTop(0);
});
</script>
本文标签:
版权声明:本文标题:javascript - Need jQuery UI dialog "window" to scroll to the top when a form inside an iframe is submitted - S 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745015017a2637784.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论