Forums

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

Simple piece of included Javascript not working for me :(

Alan Whooley October 5, 2018

Hi,

I have a simple Javascript.

alert('hello world!');

I have saved this in a file called simple.js in 

/opt/atlassian/confluence/confluence/includes/resources

 

My 'HTML Macro' contains:

<!doctype html>
<html>

<title>My Web Page</title>
<head>
<script src="/includes/resources/simple.js" type="text/javascript"></script>
<script>alert('hello world inline!');</script>
</head>
<body>
Random Text...<br>
<img src="/includes/resources/logo.png" height="30px">
</body>

</html>

The inline alert is presented by Confluence but the one that should come from the included Javascript simple.js is not. I am not a Javascript expert so I could be doing something stupid, but the same code on a standalone browser works fine.

Any advice or pointers as to why it might not be working would be appreciated. Note that Iogo.png displays fine...done as a sanity check to verify I had the path correct. The console debugger does not show anything obvious work either.

Regards

Alan

 

 

 

 

3 answers

0 votes
Timothy
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 6, 2018

You can, of course, code your Javascript to only act if the URL matches your page.

Alan Whooley October 6, 2018

Cheers. Thanks for you inputs on this. 

To explain some more, the 3rd party tool produces an index.html that references a library of Javascript and  css. The data is then actually stored in a .zip file that the Javascript extracts and displays through the index.html.

My hope was that I could place the library of Javascript and css in a central location untouched, place the index.html code in a HTML macro and update its references to the Javascript library to the new Confluence based location. How I would handle the .zip file of data would be a whole different question that I'd need to figure that out too! As mentioned, I don't want to edit the Javascript library if at all possible. Editing the index.html code is a trivial task, but having to edit multiple files in the library would be painful,and hopefully avoidable. 

From what I can see I can get the Confluence to pick up the style sheets from the central location but not the Javascript for some reason. Hence the trivial piece of code above I am using as a test. If I can't get this to execute I've no chance with the more complete solution. 

 

Best Regards 

Alan 

Timothy
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 6, 2018

If that's the case, you should consider writing a Confluence plugin to consume the endpoint that you are talking about and display the output as a functionality in Confluence.

0 votes
Alan Whooley October 6, 2018
Deleted due to repetition...
0 votes
Timothy
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 6, 2018

If you're going to do some simple Javascript, why don't you use the Custom HTML (admin/viewcustomhtml.action) functionality in Confluence?

Alan Whooley October 6, 2018

Hi,

Please correct me if I'm wrong but my understanding is that the Javascript in custom html is executed for all pages whereas I only want my Javascript executed for a single page within my Confluence environment.

In reality I am trying to embed a 3rd party HTML report that's based on Javascript into Confluence so that it lives beside several other pages on the same topic. 

 

Regards 

Alan

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events