Run JavaScript from an HTML Button Onclick Event

This is a solution to add a button anywhere on the page that would open a popup.

  • Not yet re-checked
  • Classic builder

Moved from our previous help site and not yet re-checked against the current product. Last edited Sep 20, 2024.

Screenshot for “Run JavaScript from an HTML Button Onclick Event”

This is a solution to add a button anywhere on the page that would open a popup.

Step 1

Add an HTML component to your page, open its settings, and add the following code within the source code <> tab.

Text
<div class="feedback" style="text-align: right;"><button id="feedback-btn" class="btn"> <img src="exclamation-mark.png" width="25px" height="25px" /> </button></div>
Screenshot for “Run JavaScript from an HTML Button Onclick Event”

Step 2

Save the HTML component and hover over the info icon to get the component ID.

Screenshot for “Run JavaScript from an HTML Button Onclick Event”

Step 3

Add the following code to the JavaScript tab of your page.

Text
TB.render('component_ID', function(data) {
    $('#feedback-btn').on('click', function() {
        var url = "http://www.example.com";
        var width = 960;
        var height = 1040;
        var left = screen.width - 400;
        var top = 5;
        var params = "width=" + width + ", height=" + height;
        params += ", top=" + top + ", left=" + left;
        params += ", directories=no";
        params += ", location=no";
        params += ", menubar=no";
        params += ", resizable=no";
        params += ", scrollbars=no";
        params += ", status=no";
        params += ", toolbar=no";
        newwin = window.open(url, "customWindow", params);
        if (window.focus) {
            newwin.focus();
        }
        return false;
    })
});
Screenshot for “Run JavaScript from an HTML Button Onclick Event”

Original Community Post:

Run JavaScript from an HTML button onclick event - Community Discussions / Tips and Tricks - Tadabase Community

Was this page helpful?

Something wrong or missing on this page? Tell us.