I have a .html with a standard form that lives within an iFrame. The form gets filled and then submitted with a submit button at the bottom of the form. The resulting action occurs at the top of the form and on some devices that means that the top of the form is not visible (off the top of browser window) when the button is clicked.
I have a .click event for the button and inside that event I have:
window.scrollTo(0,0);
This worked fine prior to placing the form within the iFrame, but it does not work from within the iFrame.
How can I accomplish the same from within an iFrame? I need to scroll to the top of the page, not just to the top of the iFrame. I tried the following code also:
$('html, body').animate({scrollTop: $("body").offset().top}, 500);
but it does not work either.
The HTML form is served from domain1.com, the iFrame resides in a page on domain2.com.
DOMAIN1.COM/index.html:
<html>
<script type="text/javascript">
// EVENT Handler - Form Submission
$(function () {
$("#btnSubmit").bind('click', function (event) {
...code needed to scroll to top on DOMAIN2.COM...
});
});
</script>
<body>
<form>
<input type="submit" id="btnSubmit" value="Submit" />
</form>
</body>
</html>
DOMAIN2.COM/index.html:
<html>
<body>
<iframe src="http://domain1.com/index.html"></iframe>
</body>
</html>
Please don't critique me on missing attributes of this code. I am not doing a copy/paste, I just typed it in quickly to give a general idea of what I'm trying to accomplish. I know there are essential attributes missing above. ;-)