Quantcast
Channel: Web Traffic Exchange - html
Viewing all articles
Browse latest Browse all 10

How to scroll to the top after a form submission in iframe?

$
0
0

This is not very likely scenario, but we use an iframe to embed a third-party content containing a multi-page form with a varying length of contents. The submit button on the earlier page is down near the bottom, but the resulting page is short and the content appears on the top. So, when a user submits the form the resulting page is empty as the contents are all the way on the top, and the browser is scrolled down too far. How do you get around this problem?

I did a google search, and found a couple of solutions:

1. (Recommended Solution) Add an onload="scroll(0,0);" event to the iframe.

<iframe scrolling="no" frameborder="0" style="width: 100%; height: 2000px;" src="http://www.webtrafficexchange.com/iframe/url" onload="scroll(0,0);"></iframe>

2. (Alternate Solution) If you do not have a control over the iframe, you may add the following attribute to the form element on the source page.

<form name="form" action="http://www.webtrafficexchange.com/form/action" onsubmit="parent.scrollTo(0, 0); return true">

One side effect of this solution is that the page may scroll to the top before moving on to the next page as the scroll occurs immediately, and the form submission may take a brief second to process.

Tags: 

Viewing all articles
Browse latest Browse all 10

Trending Articles