Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to execute javascript in popup page?

sm shamim May 28, 2012

I am displaying a velocity templte as a popup using the "<styleClass>trigger-dialog</styleClass>". The template is served through a servlet and it is invoked against a menu item. Now, how do I execute javascript when the popup loads?

AJS.$(document).ready(function() {} is always executing and I can not use it manipulate html elements of the popup page. Any hits would be really helpful.

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
CEDRIC ZABEL
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 29, 2012

Have you tried using

JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
    // more Javascript
});

instead of

AJS.$(document).ready(function() {
    // more Javascript
});

?

As you have seen, the jQuery ready only fires when the page is first loaded, not when popups are loaded. The JIRA.bind on JIRA.Events.NEW_CONTENT_ADDED will fire when popups get loaded.

Unfortunately, the only documentation I could find on this is https://developer.atlassian.com/display/JIRADEV/Custom+Fields+that+use+CSS+or+JavaScript+Web+Resources+in+JIRA+5.0 , and it’s not much.

sm shamim May 29, 2012

The code you shown had to be inside the onready handler.

CEDRIC ZABEL
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 29, 2012

Ah, well I knew it had to be there somewhere. I can’t say that I fully understand why it had to be in the ready handler, but the important thing is that it works for you!

0 votes
sm shamim May 29, 2012

Just having the following code did not work,

AJS.$(document).bind('dialogContentReady', function(event, dialog) {

}

It had to be put inside onready handler

AJS.$(document).ready(function() {
  AJS.$(document).bind('dialogContentReady',   function(event, dialog) {
  }
}

RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 29, 2012

i think if you change project or issue type it won't help.

CEDRIC ZABEL
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 30, 2012

I was able to use the JIRA.bind on JIRA.Events.NEW_CONTENT_ADDED technique to run Javascript when the project and/or issue type was changed. In my case, I did have to make sure that the Javascript was present before the user hit the “Create Issue” button, which basically meant including that code on every page. But it did work. And if you don’t need the popup to appear on the “Create Issue” screen, you won’t have to worry about the project and/or issue type changing.

RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 30, 2012

if you don’t need the popup to appear on the “Create Issue” screen then the above scripts well

Stefan Niedermann March 24, 2014

i think if you change project or issue type it won't help.

I have the same problem. Is there any other solution than including JS in every page? We have very very much Javascripts...

TAGS
AUG Leaders

Atlassian Community Events