How to add a custom attribute to the script tag via drupal_add_js?

by kenorb   Last Updated January 12, 2018 13:07 PM

As part of API implementation of Queue-it framework, I need to add extra custom attribute data-queueit-c into script tag, e.g.


I'm aware you can add other attributes such as defer, however this one is custom.

I've tried the following code using drupal_add_js, but without luck:

    'type' => 'external',
    'data-queueit-c' => 'MyClientID',

How this can be achieved?

Tags : 7 javascript

Answers 1

As for workaround, inline syntax can be used, e.g.

$js_code = "<script data-queueit-c='MyClientID' type='text/javascript' src='//'></script>";
drupal_add_js($js_code, 'inline');
January 12, 2018 12:41 PM

Related Questions

Use drupal.settings variables on javascript

Updated March 27, 2015 14:18 PM

Passing Javascript variable in my module file

Updated July 27, 2015 14:03 PM

Calling a contact form in a certain page

Updated August 23, 2015 17:03 PM