WordPress.org

Ready to get started?Download WordPress

Forums

Mailbag
[resolved] Change redirect... (6 posts)

  1. edtstu
    Member
    Posted 5 months ago #

    How do I add an anchor tage to the redirect URL so it snaps to the same place on the page after the reload?

    Thanks,
    Stu

    https://wordpress.org/plugins/mailbag/

  2. ArrayHQ
    Member
    Plugin Author

    Posted 5 months ago #

    Hi Stu,
    If the form submits successfully, the URL string gets a sent=1 parameter. You can detect this with JS and then scroll to the anchor where your form is.

    Add this to your theme's JS and replace #your-anchor with whatever you have your subscribe form wrapped in.

    
    // Scroll to element on div
    if(window.location.href.indexOf("sent=1") > -1) {
    	$('html, body').animate({
            scrollTop: $("#your-anchor").offset().top
        }, 300);
    }
    
    
  3. edtstu
    Member
    Posted 4 months ago #

    I added:

    <script type="text/javascript">
    // Scroll to element on div
    if(window.location.href.indexOf("sent=1") > -1) {
    	$('html, body').animate({
            scrollTop: $("#beta-signup").offset().top
        }, 300);
    }
       </script>

    to header.php

    doesn't seem to work

    I tried adding just the JS to the main.js but that isn't working either.

    Website: http://getdistilld.com/
    Theme: Agile-WP

  4. mindctrl
    Member
    Plugin Contributor

    Posted 4 months ago #

    Hey Stu,

    Try this in your header (changing the two $ to jQuery):

    <script type="text/javascript">
    if(window.location.href.indexOf("sent=1") > -1) {
    	jQuery('html, body').animate({
            scrollTop: jQuery("#beta-signup").offset().top
        }, 300);
    }
    </script>

    I tested this in my browser dev tool and it seems to work ok. Let us know.

  5. edtstu
    Member
    Posted 4 months ago #

    hmm still not working

  6. edtstu
    Member
    Posted 4 months ago #

    I used a different form plugin that doesn't refresh and uses ajax instead. Thanks anyway!

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.