Forums

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

HTML file as attachment

Luca Montagna
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 18, 2017

Hi there,

I'm currently trying to bind my HTML-file which I uploaded as attachment (filetype: text/html) in an iFrame.

But Confluence keeps downloading the HTML file instead of rendering the file.

I have to work with an iFrame because i have a bootstrap stylesheet which would cause problems if I link it directly in the HTML-Macro.

Confluence Version: 6.0.3

Do you have any suggestions to my problem?

Thanks in advantage

Luca

 

EDIT:

I forgot to say that I tried the "Example - HTML from an attachment" (https://bobswift.atlassian.net/wiki/display/HTML/HTML+Macro)

But everytime I try to write {html:script=^..........} Confluence doesn't recognize my command... Maybe I'll do something wrong...

 

EDIT2:

Nevermind... I saw that the Bob Swift HTML Macro have to be installed separately. I thought that he described the Confluence HTML Macro...

1 answer

2 votes
Nic Brough -Adaptavist-
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.
September 18, 2017

Confluence is not a web server that renders up arbitrary html.  Your file is an attachment and hence gets treated as an attachment.  If you want to render it in Confluence, you'll need to convert it to a Confluence page, or find/write a macro that can read and render an attachment.

Luca Montagna
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 18, 2017

Thank you for your answer.

I've found a solution that works for me.

I download the HTML file via JQuery ajax and write it direct in the iFrame. This should work for Google Chrome, Firefox and Internet Explorer:

<iframe id="result" style="width: 100%; height: 100vh;border:none;" scrolling="no"></iframe>
<script>
$(document).ready(function() {
$.ajax({
 method: 'GET',
 url: '/download/attachments/...',
 dataType: 'text',
 success: function(data) {
 var iframe = document.getElementById('result');
iframe = iframe.contentWindow || ( iframe.contentDocument.document || iframe.contentDocument);

iframe.document.open();
iframe.document.write(data);
iframe.document.close();
 }
});
});
</script>
Joseph Truncale
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 2, 2018

This is a little hacky, but creative and solves my problem!

Note to others:

Copy the script above into the HTML Macro (not html include) and replace the URL with your HTML attachment. 

Like Benno Vogel likes this
maxime pichot
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 22, 2020

Luca's solution works fine except for some characters like accented letters that appear as �.

Do you know how to solve this ?

P. van der Heyden
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 13, 2022

tip: Find a way to replace ASCII characters by  UFT8 characters.

Jérôme Leclère July 16, 2024

Thank you for this solution based on JQuery Ajax, it indeed works, but only if there is a single page to include.

If I put several HTML macros with this code targeting different HTML files, only the last HTML file is included in the first HTML macro, the rest is white.

Is it expected? Is there a workaround?

Benno Vogel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 15, 2024

Works like a charm, thanks!

Like Jérôme Leclère likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events