Skip to content

<script> tags in report widget templates are not executed when dashboard loads #818

Answered by bennothommo
hirisov asked this question in Q&A
Discussion options

You must be logged in to vote

Report widgets are brought in by an AJAX call, and both the original framework and Snowboard use innerHTML writes to write the HTML of the report widget into place. One of security measures of innerHTML is that it does not execute inline JavaScript, so yes, using JavaScript in your template will not work.

What you must do is load the JavaScript in an external asset with addJs, as you mentioned doing, and depending on whether you use jQuery or Snowboard, listen for the event that fires after AJAX requests are completed:

jQuery

$(document).on('render', function () {
    if (!$('#test').length) {
        return;
    }

    $('#test').html('after script run');
});

Snowboard

Snowboard.on('ajax…

Replies: 3 comments 8 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
8 replies
@hirisov
Comment options

@hirisov
Comment options

@bennothommo
Comment options

@hirisov
Comment options

@bennothommo
Comment options

Answer selected by bennothommo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #817 on January 12, 2023 01:10.