Home>Support>Add an onclick javascript to a SiteOrigin Button widget button

Add an onclick javascript to a SiteOrigin Button widget button

I have javascript code that I want to use to open a popup with a button. I’m using the SiteOrigin Button widget. The onclick script works fine in something like this in the Custom HTML widget:
Button
So I know the script is working properly.

Rather than using the Custom HTML widget, I want to use the Button widget so all of the formatting for all buttons on my page and site are the same.

In the Button widget I’m trying to put showPopup() into the onclick field under Other Attributes and SEO. It doesn’t matter what I put into this field, if I save and then reopen the widget, the contents in this field don’t appear. The javascript doesn’t run. Am I using the wrong syntax? Why is this not working?

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 6 months, 19 days ago rmniemela

    hmm… the code for the Custom HTML widget got stripped. Trying again:

    “”Button””

  2. 6 months, 19 days ago rmniemela

    Sigh..

     <button class="button" href="#" onclick="showPopup()">Button</button>
  3. 6 months, 17 days ago Alex S
    Hi, I Work Here

    Hi,

    Thanks for reaching out. For security reasons, the onclick field maintains an allowlist of popular services that provide onclick support. In the current release, it’s not possible to add to the allowlist but it will be possible in a future update via a hook called siteorigin_widgets_onclick_allowlist_functions. In the meantime, you’ll need to disable the allowlist to use other functions. This poses a security risk so I don’t recommend doing this. Regardless, that can be done using the following PHP:

    add_filter( 'siteorigin_widgets_onclick_allowlist', '__return_false' );
    

    Kind regards,
    Alex

  4. 6 months, 17 days ago rmniemela

    ok, thanks. I’ll do a workaround.

  5. 6 months, 17 days ago Andrew Misplon
    Hi, I Work Here

    Thanks for your feedback and understanding.

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More