Execute javascript code when page is loaded Edited

Hi,

I'm writing a plugin that adds some Information to the issue details view.

Therefore I'm using javascript code to add interactions.

my vm-template looks roughly like this (first HTML-Elements then the javascript parts)

<div id="myContent">my content</div>

<script>
document.getElementById("myContent").innerHTML = "my new content";
</script>

the point is that JIRA seems to reassemble the order of the elements. When I test my plugin the getElementById() always fails, because the corresponding element is not yet available in the DOM.

btw. using jQuery(document).ready(function() {...}); doesn't make any difference. Using some blocking interaction in my javascript (e.g. alert()) shows that when it's executed the JIRA-page is not yet complete. It is incomplete until the blocking event of my code returns (see attached screenshot)

So my question is: how can I ensure, that certain parts of the DOM are available when my script is executed.blockingEvent.PNG

2 answers

0 vote
Thomas Schlegel Community Champion Apr 05, 2017

Hi Florian,

Questions about developing Plugins for Atlassian Products should better be asked in the Atlassian Developer Community Platform  

Thank you 

Thomas

0 vote

Ideal thing to do is to use a JS file and load it as a resource using the web resource module. And of course, add your code in the ready function because you want to execute it only after the page is loaded.

See https://developer.atlassian.com/jiradev/jira-platform/building-jira-add-ons/jira-plugins2-overview/jira-plugin-module-types/web-resource-plugin-module  

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 21, 2018 in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

1,194 views 10 18
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you