Javascript in Static HTML blocks

kc99
Giga Expert


Hello,

I wanted to insert some Javascript into a couple of our Static HTML content blocks but, on saving, the script is comments out with a CDATA tag.

Can someone please tell me whether this is intentional?

 

The Javascript is intended to simply add another paramater to the incoming URL.

I have read that we may be able to add the the "extended_valid_elements" setting within the TinyMCE settings but I wouldn't want to risk this.

 

If I can't place this in the content block can someone please tell me if there is another way of doing this?

Many thanks,

Keiron.

4 REPLIES 4

User140988
Kilo Guru

You can use Dynamic content block which supports HTML and javascript as well


Many thanks for the quick reply Chandana.


I've now added   the Javascript function to a test Dynamic Block and followed it by the HTML.


In the HTML one of the buttons' 'onClick' event targets the JS function but it I get this error (in Firefox):



ReferenceError: myTestFunction() is not defined



Do I need to place the function elsewhere for an onClick event to work?


Many thanks,


Keiron.


you can write the javascript block in the same dynamic content, just use the below format inside the jelly code.



<script>


function myTestFunction(){



function definition...



}


</script>


My apologies Chandana - I was too hasty with my reply.


I had a second curly bracket which it obviously didn't like.


Many thanks for your help - I will now mark it as correct,


regards,


Keiron.