JavaScript not working in header file

This is the right place to report general bugs, make suggestions or ask for help.
Post Reply
ClarusAD
Posts: 3
Joined: Sun Oct 05, 2025 9:10 am

JavaScript not working in header file

Post by ClarusAD » Sun Oct 05, 2025 11:19 am

Hello,
When i write some JS code in the header file
flatpress/fp-interface/themes/leggero/header.tpl
For example :

Code: Select all

{literal}<script> alert() </script>{/literal}
That doesn't work, and i don't understand why…

Can someone help me ?
Thank-you in advance

User avatar
fraenkiman
Posts: 368
Joined: Thu Feb 03, 2022 7:25 pm
Location: Berlin, Germany
Contact:

Re: JavaScript not working in header file

Post by fraenkiman » Mon Oct 06, 2025 12:38 am

Hello ClarusAD,

Try using

Code: Select all

{literal}<script nonce="{/literal}{$smarty.const.RANDOM_HEX}{literal}">…</script>{/literal}
Or with externally integrated JS:

Code: Select all

<script nonce="{$smarty.const.RANDOM_HEX}" src="{$smarty.const.BLOG_BASEURL}fp-interface/themes/leggero/res/custom.js" defer></script>
Otherwise, your browser will block the execution of the inline script.
Screenshot 2025-10-06 024126.png
Screenshot 2025-10-06 024126.png (102.38 KiB) Viewed 199 times
Have a great start to the new week.
Best regards,
Frank
:pencil: You are strong in PHP and Java Script? :point_right: Then help us to improve FlatPress. :point_left:

:exploding_head: Looking for ideas, templates, examples and answers to frequently asked questions?
:bulb: You'll find it here.

My :de: FlatPress-Blog: https://frank-web.dedyn.io

ClarusAD
Posts: 3
Joined: Sun Oct 05, 2025 9:10 am

SOLVED Re: JavaScript not working in header file

Post by ClarusAD » Mon Oct 06, 2025 4:42 pm

Thank-you Fraenkiman, you're a king ! The soluce was to add the "nonce" part :

Code: Select all

{literal}<script nonce="{/literal}{$smarty.const.RANDOM_HEX}{literal}">…</script>{/literal}

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 0 guests