JavaScript using the HTML macro returns nothing

Good morning,

 

I am very new to JavaScript, but am trying to get a Statuspage.io private page to display as a widget on a Confluence page. Confluence is a core tool for our department, and so there is great benefit to having the Statuspage feed displaying on pages for various team spaces.

 

I have created a new page new page on my personal space, interted the HTML macro, and then inserted the following code;

 

<script type="text/javascript" src="https://cdn.statuspage.io/se-v2.js"></script>
<script>
	var sp = new StatusPage.page({ page : 'XXXXXXXXXXpx', apiKey : 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX' });
	sp.incidents({
 		success : function(data) {
		console.log(data.incidents[0].name);
    		}
	  });
</script>

 

The publishes fine, but the macro returns no data from Statuspage.io

 

I know I must be missing something obvious, but need a bit of guidance please. I have read the support document for using the HTML macro, but didn't get further with it, so any advice is greatly appreciated.

 

Regards,

Aubrey

2 answers

1 accepted

It's too late for javascript to execute in the body of a macro - the <head> section of the code is effectively ignored because the <head> of the page has already been completed before the body of the page starts.

 

https://community.atlassian.com/t5/Confluence-questions/HTML-macro/qaq-p/310168

Best practice is to store Javascript towards the end (before the end body tag).

However, if the Statuspage is in trial mode, the widget won't work - this happened to me several times (I manage multiple pages for Symantec). Admittedly haven't tried to embed it into a Confluence page though.

Thanks,
Nick

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Dec 18, 2018 in Confluence Cloud

Happy holidays from our team to yours!

Hi Community!  2018 was filled with changes for our team, both big and small, and we've taken a lot of time to both celebrate our wins and recognize areas of improvement. One thing that we're a...

475 views 3 18
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you