Forums

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

Use of Jquery in Confluence

Adolfo Casari
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.
March 8, 2012

Is it possible to use Jquery in a confluence page (version 4.1)?

I found this user macro, Jquery , but it doesn't seem to work with Confluence 4.1

Thank you,

2 answers

1 accepted

9 votes
Answer accepted
Andrew Frayling
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.
March 8, 2012

Hi Adolfo,

Could you just use the bundled {html} macro> E.g.:

{html}
<script>
AJS.toInit(function() {
   AJS.$("a").click(function() {
     alert("Hello world!");
   });
 });
</script>
<a href="#">My Link</a>
{html}

I tested the above on my local 4.1.4 Confluence instance and it worked. {html} macro is disabled by default, but can be enabled via Browse -> Confluence Admin -> Plugins -> Manage Existing -> System -> Confluence HTML Macros

Hope that helps,

Andrew.

Adolfo Casari
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.
March 8, 2012

Thank you Andrew. This is what I was looking for.

David at David Simpson Apps
Atlassian Partner
April 25, 2012

@Andrew was just giving an example here. Using the bundled {html} macro means that anyone with edit access can add naughty wicked JavaScript code into your pages -- that's why it's disabled by default. Use it with care.

Martin Cleaver
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.
August 2, 2012

BTW: I can confirm that:

&lt;script&gt;
AJS.toInit(function() {
   AJS.$("a").click(function() {
     alert("Hello world!");
   });
 });
&lt;/script&gt;

In a user macro works just fine. (Of course you have to click any A link to see the effect)

Martin Cleaver
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.
August 2, 2012

BTW - I can confirm that:

&lt;script&gt;
AJS.toInit(function() {
   AJS.$("a").click(function() {
     alert("Hello world!");
   });
 });
&lt;/script&gt;

In a user macro works just fine.


adam-roth March 25, 2013

@Adolfo - If you've given edit access to people who *want* to add naughty wicked JavaScript code to wiki pages, doesn't it follow that you're doing it (managing your Confluence users) very, very wrong? Confluence security happens at the adminstrator level, not the macro level.

Yagnesh Bhat
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.
October 4, 2018

Can we make AJAX calls from within an HTML macro? Its giving me CORS errors when I do so, any idea?

5 votes
Matthew J. Horn
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.
April 24, 2012

I'll just add some info because I've been hunting around and making a few discoveries recently.

****** What is the current version of jQuery used in Confluence? ******

This page:

http://forums.atlassian.com/thread.jspa?threadID=30940

Says that I should be able to get my version by doing this in the header custom HTML section:

console.log(AJS.$().jquery);

but I couldn’t find it in the logs (might be a log-level setting), so I did this instead:

alert(AJS.$().jquery);

Results in a popup that shows:

"1.5.2"

(I am using Confluence 4.1.2)

****** Using a different version of jQuery than the one provided with Confluence ******

This page provides a link to how to use two versions of jQuery side by side:

https://answers.atlassian.com/questions/19782/jquery-1-6

****** Other mentions of "current" version of jQuery ******

This page:

https://developer.atlassian.com/display/CONFDEV/Including+Javascript+and+CSS+resources

Mentions that jQuery 1.4.2 is included in Confluence 3.3+.

Also mentions that you need to include the following in your Velocity template to use the library:

#requireResource("confluence.web.resources:jquery")

I assume this is out of date as it doesn't appear to be necessary.

This page:

http://confluence.atlassian.com/display/CONF30/Including+Javascript+and+CSS+resources#

mentions that jQuery version 1.2.6 is the current version.

There does not appear to be a newer version of that page.

****** Atlassian.js file? ******

This page:

https://developer.atlassian.com/display/CONFDEV/Confluence+UI+Guidelines

mentions an Atlassian.js file. I could not find any actual file of that name in the source or on the server or in the communication with the server when a page is downloaded.

There are also several mentions of atlassian.js in the test files in the Confluence source. I suspect it’s generated and then included in the batch.js files, but I could not find any documentation that describes the batch.js file process.

A couple of the batch.js files include jQuery UI elements and other definitions and all seem to mention version 1.8.11.

Lots of dependencies on the following in the web-resources plugin file in the \confluence\WEB-INF\lib\confluence-4.1.2.jar file:

<dependency>confluence.web.resources:ajs</dependency>

Anyway, I hope this helps someone else who might come along and try to understand the relationship between Confluence and jQuery.

matthew horn

verivo.com

Coline Macorol November 16, 2017

@Matthew J. Horn,

Thanks man, really useful information about jQuery!

Andrei June 5, 2018

Confluence 6.9 (released May 2018) still uses jQuery 1.7.2 (released 6 years ago on March 2012).

Like akira-yamamoto-fil likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events