jquery macro and confluence

I have installed jquerty macro on my confluence 3.4. and i’m trying to run some simple code

{jquery:markup=wiki}
{html}
<head>
<script type="text/javascript">
function displaymessage()
{
alert("Hello World!");
}
</script>
</head>

<body>
<form>
<input type="button" value="Click me!" onclick="displaymessage()" />
</form>

<p>By pressing the button above, a function will be called. The function will alert a message.</p>

{html}
{jquery}

...everything works fine on PREVIEW view (Hello World string appears) but when i save my page and press the "Click me" button nothing happened.

Any idea why?


					
				
			
			
			
				

2 answers

1 accepted

1 vote
David Simpson Community Champion Sep 29, 2011

Some things...

You don't seem to be using jQuery at all, so why both with the {jquery} macro. Also, this is being displayed in the page, so don't add the head or body tags.

Try this:

{html}
<script>
  function displayMessage(){
      alert('Hello World!');
  }
</script>
<form><input id="clickMeInput" type="button" value="Click me!" onclick="displayMessage()" /></form>

<p>By pressing the button above, a function will be called. The function will alert a message.</p>
{html}

If you want to use jQuery, Atlassian already bundle it in Confluence, but their version is referenced using AJS.$ rather than just $.

Try this:

{html}
<script>

  AJS.toInit(function(){ // use instead of $(document).ready()
    AJS.$('#clickMeInput').click(function(){
      alert('Hello World!');
    })
  })

</script>

<form><input id="clickMeInput" type="button" value="Click me!" /></form>
 
<p>By pressing the button above, a function will be called. The function will alert a message.</p>
{html}

this is macro security issue or jquery macro is not compatible with 4.3?

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,831 views 27 11
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