How to prevent TW to strip my onclick

131 views
Skip to first unread message

Florian Cauvin

unread,
Mar 22, 2021, 6:04:51 PM3/22/21
to TiddlyWiki
I use tiddlywiki to render a set of static html pages!
In a tiddler, I'm adding some html <button> tags with some very simple "onclick=..." in order to provide some small basic interactivity to this static site. But TW rendering strips all the onclick stuff from the rendered html. How could I force TW not to remove my "onclick" ?

Mat

unread,
Mar 23, 2021, 4:45:01 AM3/23/21
to TiddlyWiki
I'm not really the person to answer this but FWIW: Yes, the stripping of all JS is intentional for security reasons. You can get around this by, for example, creating a plugin. There were questions about this just within the last 2-3 weeks.... If I recall, Simon Baird asked about where to find guidance on how to create plugins and I think Mark S also had a similar question.

BTW, someone qualified should update the docs for this to clarify why no JS and how to deal with it.
<:-)

Jeremy Ruston

unread,
Mar 23, 2021, 4:51:07 AM3/23/21
to tiddl...@googlegroups.com
Hi Florian

There's no easy way around that limitation of the default static site rendering templates. You may find the easiest approach is to give your buttons CSS classes or IDs for identification, and then use a separate JS file to trap events at the document level, or to set up event handlers after the page has loaded.

Best wishes

Jeremy


On 22 Mar 2021, at 22:04, Florian Cauvin <florian...@gmail.com> wrote:


I use tiddlywiki to render a set of static html pages!
In a tiddler, I'm adding some html <button> tags with some very simple "onclick=..." in order to provide some small basic interactivity to this static site. But TW rendering strips all the onclick stuff from the rendered html. How could I force TW not to remove my "onclick" ?

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/8820f22e-e5c3-4aec-8bbf-0d380e025980n%40googlegroups.com.

Florian Cauvin

unread,
Mar 23, 2021, 10:52:39 AM3/23/21
to TiddlyWiki
So, I still wanted to have some JS within (some) tiddlers to my. So I just went with a "workaround": I added a marker (let's say ZZZZ) and then in my tiddlers I can add <ZZZZscript> </ZZZZscript> ZZZZonscript=... and that won't be stripped. Then, I just added a simple 'sed' one-liner in my build script to remove the ZZZZ marker from html files in TW's output directory. This is an ugly workaround, but it works without trying to go change TW rendering process.

Florian Cauvin

unread,
Mar 23, 2021, 11:18:15 AM3/23/21
to TiddlyWiki
> ugly workaround ...
Actually, it worked well for "onclick" attributes, and for <script> tag, I had to do even more uglier trickery than that ;-)
Message has been deleted

BJ

unread,
Mar 26, 2021, 5:27:43 PM3/26/21
to TiddlyWiki
See here for a macro  to endable script tags:

BJ
Reply all
Reply to author
Forward
0 new messages