Can't use script tag in user macros

Stuart Bennett November 16, 2011

Hi,

Does anyone know how you can include an externally hosted javascript file from a user macro?

I am finding that the <script> tag completely kills the user macro.

All I want to be able to do is include a standalone javascript file like:

<script type="text/javascript" src="/some/directory/someFile.js">

Any help or suggestions would be greatly appreciated.

7 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

8 votes
Answer accepted
Ryan Musselwhite November 16, 2011

Found the answer!!

User macros die when you do something as follows:

<script type="text/javascript" src="src.js"></script>

If you include the script tags with a newline before the start and end it fixes it, example:

<script type="text/javascript" src="src.js">

</script>

Hope this helps!

Stuart Bennett November 16, 2011

THAT'S THE SOLUTION!

If only Atlassian support could have told me that.

Looks like a strange bug in version 4.0. Previous versions didn't have this issue.

Like Tim Eddelbüttel likes this
Steve Goldberg
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 15, 2013

Sorry to resurrect an old thread but I'm having a similar issue and this doesn't work for me.

When I put some JS between two <script> tags it gets mangled with some "//<![CDATA[" tags (even when I put in an extra line as you suggest. Does the above solution still work for you? (I'm trying to implement a Twitter feed and the Widget Connector's not working.)

Simon Tost _TNG_ April 17, 2019

Probably only of limited use, but scripted user macros from ScriptRunner for Confluence have no such issues.

1 vote
Sandro Herrmann [Communardo]
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.
November 16, 2011

Hello,

you can append the needed Javascript and css via the Global Administration -> Custom HTML -> "At the end of the BODY".

I know with this way you split your usermacro code apart but it works. :)

Stuart Bennett November 16, 2011

I would only want the javascript file to be loaded when the macro is inserted on a page. Thanks though.

1 vote
Oli S
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.
November 16, 2011

The correct way is to register your javascript in you atlassian-plugin.xml file as resource and "inlcude" this resource in your velocity file.

Atlassian Documenation:Including Javascript and CSS resources

This is the way, I do it every time ;-)

Stuart Bennett November 16, 2011

Ok, thanks anyway. You got my hopes up then.

Oli S
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.
November 16, 2011

Oh now I read, that you wrote an user macro, than my answer doesn't fir your needs, sorry

0 votes
Guillaume Guillaume January 13, 2014

Thank you so much Ryan, your solution worked for me too, on Confluence 4.2.8.

0 votes
Stuart Bennett November 16, 2011

Also I tried adding jus

0 votes
Stuart Bennett November 16, 2011

Yes, the script include does appear to work because the javascript file is loaded, but then the rest of the macro fails after that point. I have even tested including a blank javascript file and that also broke the macro.

0 votes
Ryan Musselwhite November 16, 2011

I am having issues with this as well. I had a ticket open but Atlassian said as it's custom they cannot provide support.

It appears to break all content after the <script> tags.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events