[Support request] Add Javascript To Button ?

Home Forums Support [Support request] Add Javascript To Button ?

Home Forums Support Add Javascript To Button ?

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #2219722
    Jason

    A 3rd party contact form plugin allows me to use this code to trigger a pop up:

    < a href = “void (0) ” >Yes! I Want This!

    How do I insert this code inside a Generate press button?

    I can overwrite the button block code starting at: href=”

    But I also get a block editor error, where WordPress prompts me to correct the code.

    Is there a cleaner way to put this code inside a button?

    #2219831
    Leo
    Staff
    Customer Support

    Hi Jason,

    I believe this should help:
    https://wordpress.org/support/topic/adding-javascript-attributes-to-buttons/#post-13313670

    Let me know 🙂

    #2219917
    Jason

    Hi Leo –

    Thank you for your feedback.

    If I understand correctly, I would add a data attribute and drop the Java there?

    #2220009
    David
    Staff
    Customer Support

    Hi there,

    which plugin are you using that wants the void(0) href ? And is there a page of its documentation where it states that?

    We can then advise on the best option.

    #2222268
    Jason

    The plugin is from the email marketing company Birdsend.

    The Birdsend plugin provides a text link to trigger an opt-in pop-up. The text link works, without error. Here is the code:

    <a href="javascript:void(0)" data-birsend-form="100AAA">DOWNLOAD THE CHECKLIST</a>

    My goal is to insert the code into the GeneratePress theme button style. This is what I attempted, which works – but also gives me a block error warning:

    <a class="gb-button gb-button-c93da5fe gb-button-text button-effect" href="javascript:void(0)" data-birsend-form="100AAA">DOWNLOAD THE CHECKLIST</a>

    The error is what prompted me to reach out.

    #2222309
    David
    Staff
    Customer Support

    The editor won’t allow edits to a Blocks HTML – as it has to be validated.
    And to add the data- attribute to that block require GenerateBlocks Pro.
    Its an option under the Advanced tab.

    Also worth checking first that adding javascript:void(0) to the blocks Link field is ok. You can inspect the button on the front end to see that.

    If you don’t use Pro then you would need to write some HTML using a HTML Block for your button. And then style it with some CSS. Let us know if you need assistance with that.

    #2325760
    Jason

    I have GenerateBlocks Pro, but I’m still unsure how to install the java into a button.

    <a href="javascript:void(0)" data-birdsend-form="100AAA">Yes! I Want This!</a>

    If it helps this script references the Birdsend email marketing plugin installed on my site.

    Again, this works perfectly as text. I just want to put that text in a button.

    #2326164
    David
    Staff
    Customer Support

    If you have GB Pro then:

    1. Select the GB Button.
    2. In the Link field ( from the button toolbar ) add: javascript:void(0)
    3. In Advanced > Add Attribute you can add the attribute: data-birdsend-form and the value eg, 100AAA

    #2326615
    Jason

    That worked! I appreciate your help. Thank you.

    #2326849
    David
    Staff
    Customer Support

    Awesome – glad to hear that !

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.