How to adjust width and height of iframe to fit with content in it in Confluence On-Demand

I'm developing a Dynamic content macro for Confluence Cloud that returns a dynamic HTML table.

Dynamic Content Macro documentation says "If the size of the macro output content size is dynamic, call AP.resize(w,h) immediately after the DOM of your iframe is loaded."

To retrieve width and height of the content, I found the following code on Internet:

var newheight = document.getElementById(id).contentWindow.document .body.scrollHeight; 
var newwidth = document.getElementById(id).contentWindow.document .body.scrollWidth;

But the frame id is generated dynamically and is not accessible through Context Parameter

So, how can I adjust i frame width and height to fit with content inside a dynamic content macro ?

Thanks

Xavier

1 answer

1 accepted

1 vote

I believe that the simplest method is to just use AP.resize() from inside your iFrame. Like so my Sketchfab for Connect addon does.

Robert, Thanks. It works fine if I don't declare parameter height in atlassian-connect.json. I will ask Atlassian to describe AP.resize() API behavior when there is no parameter (https://developer.atlassian.com/static/connect/docs/latest/javascript/module-AP.html)

AP.resize('100%', 'calc(100vh - 160px)');

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

2,921 views 27 12
Join discussion

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