Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to include javascript in web-item?

Joseph Tyrrell
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 31, 2011

I call an external .vm file from my plugin. The .vm file contains Java Script which opens a new browser and sets the focus to the new browser page.

My Atlassian-plugin.xml, which is the file you build the plugin with and which contains the <link> tags, looks like this:

{code}

<web-item key="rally_link" name="Rally Hosted Web Site" section="links_link/links_section" weight="10">

<label>Rally - Hosted Scrum Tool</label>

<link >/templates/rally.vm</link>

</web-item>

{code}

My .vm files contents look like this:

{code}

<!-- Open a new browser window from a plugin -->
<html>
<head>
<script type="text/javascript">
function load()
{
newwindow = window.open("https://rally1.rallydev.com/slm/login.op", "newwindow")
<!-- have JIRA window go back a page -->
history.go( -1 );
<!-- Set focus to the new page -->
newwindow.focus();
<!-- Move the new page to the forground -->
newwindow.resizeTo(875, 320);
newwindow.moveTo(0,0);
return false;
}
</script>
</head>

<body
onload="load()">
</body>
</html>

{code}

*.vm files are located here on the server:

/webapps/ROOT/WEB-INF/classes/templates

Hope this helps

4 answers

1 accepted

0 votes
Answer accepted
Joseph Tyrrell
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 15, 2011

This was more of an informational blog of how I got this to work and not really a question. The code works as displayed. My vm file is located here on my JIRA server: /tomcat/apache-tomcat-6.0.29/webapps/ROOT/WEB-INF/classes/templates

2 votes
MatthewC
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.
September 25, 2012

You should be able to do it straight from the web-item....

&lt;web-item key="rally_link" name="Rally Hosted Web Site"  section="links_link/links_section" weight="10"&gt;
    &lt;label&gt;Rally - Hosted Scrum Tool&lt;/label&gt;
&lt;link linkId="rally_linkid"&gt;javascript:window.open('https://rally1.rallydev.com/slm/login.op', 'newwindow').focus();&lt;/link&gt;
&lt;/web-item&gt;

Chris K.
Contributor
December 15, 2014

Does this still work in JIRA 6? When I try to put the javascript directly in web-item (using the example from above), when I click the button it just goes to a blank page with the following URL: http://localhost:2990/jirajavascript:window.open('https://rally1.rallydev.com/slm/login.op',%20'newwindow').focus();

0 votes
Nitin Sinha
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 5, 2016

How can I make this work ? I want to change name each time this button is clicked

<ac:macro ac:name="web-item">
<ac:parameter ac:name="key">selector-for-button</ac:parameter>
<ac:parameter ac:name="section">system.content.button</ac:parameter>
<ac:parameter ac:name="item">pagefavourite</ac:parameter>
<ac:parameter ac:name="force">true</ac:parameter>
<ac:macro ac:name="link">
<ac:parameter ac:name="linkId">selector-for-button</ac:parameter>
</ac:macro>
<ac:rich-text-body>s</ac:rich-text-body>
</ac:macro>

 

and in Javascript section, I have -

 

AJS.toInit(function() {
$('.selector-for-button').click(function() {
alert('Hello!');
});
})

0 votes
CITnet CITnet December 15, 2011

Your template file must reside with the plugin I think.

Have you tried moving the file ?

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events