Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Dynamically Embedding Service Desk Widget

Does anyone know why when I insert the widget embed directly into the html file, it works.. but if I do it dynamicaly via JavaScript, it loads the js file but does not display the widget?

Inserting this directly into the <head> works:
<script type="text/javascript" data-jsd-embedded data-key="####" data-base-url="" src=""></script>


This does not:

const feedbackScript = document.createElement('script');

feedbackScript.type = 'text/javascript';
feedbackScript.setAttribute('data-jsd-embedded', null);
feedbackScript.setAttribute('data-key', '####');
feedbackScript.setAttribute('data-base-url', '');


It DOES actually load the embed.js and runs (I get a response if I set an onload callback) but I see no widget.

4 answers

We're using Google Tag Manager and this was the solution we worked out:

function jiraHelpdesk(callback) {
var jhdScript = document.createElement('script');
jhdScript.type = 'text/javascript';
jhdScript.setAttribute('data-jsd-embedded', null);
jhdScript.setAttribute('data-key', '####');
jhdScript.setAttribute('data-base-url', '');
if(jhdScript.readyState) { // old IE support
jhdScript.onreadystatechange = function() {
if ( jhdScript.readyState === 'loaded' || jhdScript.readyState === 'complete' ) {
jhdScript.onreadystatechange = null;
} else { //modern browsers
jhdScript.onload = function() {

jiraHelpdesk(function() {
var DOMContentLoaded_event = document.createEvent('Event');
DOMContentLoaded_event.initEvent('DOMContentLoaded', true, true);
Deleted user Mar 27, 2020

Thanks a lot. It helped me as well

Thank you, this helped me a lot.

This is a lifesaver. Thanks a lot!

Atlassian needs to put this on their main support page! Thanks!

Thanks for sharing. This was helpful.

Thanks a lot! Works quite well.

if you read the received code, it expects an event

Run this after it has loaded

var DOMContentLoaded_event = document.createEvent("Event")
DOMContentLoaded_event.initEvent("DOMContentLoaded", true, true)


this might be helpful

for what is worth this is my react solution currently working for me.

Note I load the script/widget conditionally only if its internal staff 



import { useEffect } from 'react';

const useScript = (url, user) => {

  useEffect(() => {

    if (user !== null) {
      if (user.is_internal_staff) {

        const script = document.createElement('script');

        script.src = url; = 'jiraWidget';
        script.setAttribute('async', true);
        script.setAttribute('data-jsd-embedded', '');
        script.setAttribute('data-key', "XXXXXXXX");
        script.setAttribute('data-base-url', "");


        script.addEventListener('load', (event)=>{
          window.document.dispatchEvent(new Event("DOMContentLoaded", {
            bubbles: true,
            cancelable: true
        return () => {
    else {
      // do nothing
  }, [url, user]);

export default useScript;

Then to use it 

import useScript from '../hooks/useScript';
useScript('', user); //pasing the url and the user

Since initEvent is deprecated it's better to use the Event constructor like this:

window.document.dispatchEvent(new Event("DOMContentLoaded", {
bubbles: true,
cancelable: true

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events