Is it possible to load a attached file via javascript?

Elisabeth Friedrich April 11, 2012
{html}
<html>
	<head>
		<title>hello</title>
	</head>
	<body>
		<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
			<script type="text/javascript">
			$ (document).ready(function() {
				 $.get("hello.txt", function(msg) {
					var textArray = msg.split("\n");
			var zufall = Math.round ( ( textArray.length - 1 ) * ( Math.random() ) );

			$('body').append('<p>' + textArray[zufall] + '</p>');
				});
			});
		</script>
	</body>
</html>
{html}

this piece of code is a random generator!

if I use it on a normal html-page, it works fine, but is it possible to use it on a confluence page within the html-macro?

"hello.txt" is an attached file.

1 answer

1 accepted

0 votes
Answer accepted
Elisabeth Friedrich April 11, 2012

I found a different solution for it:

I've got a page, that looks like this:

{html}

<script type="text/javascript">
var text = new Array(
	"hier steht dein erster text.",
	"text no. 2",
	"text no. 3",
	"usw."
);
var zufall = Math.round ( ( text.length - 1 ) * ( Math.random() ) );
document.write('<p>' + text[zufall] + '</p>');
</script>

{html}

and now I'm using this page via the include-macro.

The intension was, to avoid having the array on the same page, because it will get extremly large!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events