Form scrolling to the top of the webpage when submitting

  • Viktor_viktor
    Asked on September 8, 2021 at 1:13 PM

    Hi,

    On the page listed below please see that our form does not immediately re-direct to its intended destination.

    Instead, it first sends the user to the top of the page, THEN after a brief delay the re-direct occurs. Please see this quick video here: https://www.loom.com/share/bf3cccd21ac4409287802e5b42824c7d

    Is there anything we can do to preclude the re-direct from sending people to the top of the page? An extra piece of code? Or something different?

    Please advise. Thank you.

  • David JotForm Support Manager
    Replied on September 8, 2021 at 8:10 PM

    Thank you for contacting us. The redirection takes a couple of seconds, the form should not jump to the top of the web page, it should stay there in the submit button until it redirects.

    I see you are using the Embed code, please try adding "?nojump" at the end of the form URL to prevent the auto scrolling, so use this code instead:

    <script type="text/javascript" src="https://form.jotform.com/jsform/210827646264257?nojump"></script>
  • Viktor_viktor
    Replied on November 3, 2021 at 3:45 AM

    Thanks for your support! We've implemented the piece of code you suggested, but it didn't change anything unfortunately. Do you have any other ideas?

  • Billy JotForm Support
    Replied on November 3, 2021 at 6:30 AM

    Kindly try using the iframe code below and see if that helps:

        <iframe
    id="JotFormIFrame-212356365888266"
    title="Form 01 [DE]"
    onload="window.parent.scrollTo(0,0)"
    allowtransparency="true"
    allowfullscreen="true"
    allow="geolocation; microphone; camera"
    src="https://form.jotform.com/212356365888266"
    frameborder="0"
    style="
    min-width: 100%;
    height:539px;
    border:none;"

    scrolling="no"
    >

    </iframe>

    Otherwise, please use the one below:

        <script type="text/javascript">
    var ifr = document.getElementById("JotFormIFrame-212356365888266");
    if (ifr) {
    var src = ifr.src;
    var iframeParams = [];
    if (window.location.href && window.location.href.indexOf("?") > -1) {
    iframeParams = iframeParams.concat(window.location.href.substr(window.location.href.indexOf("?") + 1).split('&'));
    }
    if (src && src.indexOf("?") > -1) {
    iframeParams = iframeParams.concat(src.substr(src.indexOf("?") + 1).split("&"));
    src = src.substr(0, src.indexOf("?"))
    }
    iframeParams.push("isIframeEmbed=1");
    ifr.src = src + "?" + iframeParams.join('&');
    }
    window.handleIFrameMessage = function(e) {
    if (typeof e.data === 'object') { return; }
    var args = e.data.split(":");
    if (args.length > 2) { iframe = document.getElementById("JotFormIFrame-" + args[(args.length - 1)]); } else { iframe = document.getElementById("JotFormIFrame"); }
    if (!iframe) { return; }
    switch (args[0]) {
    case "scrollIntoView":
    iframe.scrollIntoView();
    break;
    case "setHeight":
    iframe.style.height = args[1] + "px";
    break;
    case "collapseErrorPage":
    if (iframe.clientHeight > window.innerHeight) {
    iframe.style.height = window.innerHeight + "px";
    }
    break;
    case "reloadPage":
    window.location.reload();
    break;
    case "loadScript":
    if( !window.isPermitted(e.origin, ['jotform.com', 'jotform.pro']) ) { break; }
    var src = args[1];
    if (args.length > 3) {
    src = args[1] + ':' + args[2];
    }
    var script = document.createElement('script');
    script.src = src;
    script.type = 'text/javascript';
    document.body.appendChild(script);
    break;
    case "exitFullscreen":
    if (window.document.exitFullscreen) window.document.exitFullscreen();
    else if (window.document.mozCancelFullScreen) window.document.mozCancelFullScreen();
    else if (window.document.mozCancelFullscreen) window.document.mozCancelFullScreen();
    else if (window.document.webkitExitFullscreen) window.document.webkitExitFullscreen();
    else if (window.document.msExitFullscreen) window.document.msExitFullscreen();
    break;
    }
    var isJotForm = (e.origin.indexOf("jotform") > -1) ? true : false;
    if(isJotForm && "contentWindow" in iframe && "postMessage" in iframe.contentWindow) {
    var urls = {"docurl":encodeURIComponent(document.URL),"referrer":encodeURIComponent(document.referrer)};
    iframe.contentWindow.postMessage(JSON.stringify({"type":"urls","value":urls}), "*");
    }
    };
    window.isPermitted = function(originUrl, whitelisted_domains) {
    var url = document.createElement('a');
    url.href = originUrl;
    var hostname = url.hostname;
    var result = false;
    if( typeof hostname !== 'undefined' ) {
    whitelisted_domains.forEach(function(element) {
    if( hostname.slice((-1 * element.length - 1)) === '.'.concat(element) || hostname === element ) {
    result = true;
    }
    });
    return result;
    }
    };
    if (window.addEventListener) {
    window.addEventListener("message", handleIFrameMessage, false);
    } else if (window.attachEvent) {
    window.attachEvent("onmessage", handleIFrameMessage);
    }
    </script>


    Let us know if you're still having the same issue so we can escalate the problem to our backend developers.

    We'll be waiting for your response.


  • Viktor_viktor
    Replied on November 8, 2021 at 12:22 AM

    Thanks a lot Billy! We'll try that and keep you posted!