Another code sample.  Drag the attached to TiddlyWiki.com .

The "Random HTML" tiddler is a patchwork of code bits I scammed from the 
web.  This Tiddler has the javascript needed to get a random value from a 
comma-separated-value list and present that value.

The "Getting Random Values" tiddler puts in a variable ("vReplacement") a 
comma-separated-value list of tiddler titles, for all tiddlers having 
"HTML" in the title.  *(Yeah, I could have been a little bit more creative 
and put together something much more practical.)*

The "source document" for the iFrame  in "Getting Random Values" alters the 
transcluded HTML (from "Random HTML" tiddler) by substituting a keyword in 
the HTML ("CsvList") with the value of the "vReplacement" variable.

So this little sample code pattern demonstrates how an iFrame can show 
dynamically created/modified HTML+javascript.







On Monday, August 16, 2021 at 11:55:46 AM UTC-3 Charlie Veniot wrote:

> Updated one of the tiddlers in the JSON package.  New version attached.
>
> The addition highlighted below:
>
> <body>
>   <div id="clockDiv"></div>
>   <script>
> *document.oncontextmenu = function() { *
> *    return false; *
> *};*
>     let clockEl = document.getElementById("clockDiv");
> ...
>
> The reason for the added code:  block access to the back button in the 
> iFrame (by blocking access to the entire menu), which winds up performing 
> the back button operation on the entire browser page.
> On Sunday, August 15, 2021 at 11:27:41 PM UTC-3 Charlie Veniot wrote:
>
>> I don't know what made me think of this.
>>
>> In case this has not been brought up in a while (I doubt this is new to 
>> seasoned folk) ...
>>
>> I was thinking: could I use an iFrame to include simple javascript in a 
>> tiddler without getting into macros or plugins that enable javascript.
>>
>> And, if I could, then could I set things up so that the iFrame is showing 
>> javascript dynamically created by the tiddler ?
>>
>> So here is a way to show a digital clock in TiddlyWiki, for 
>> non-programmers who just want to copy and paste javascript code from the 
>> web without figuring out how the javascript code works :
>>
>> Put this in a brand new tiddler:
>>
>> *<$vars* *vSrcDoc*={{{ [[<body>  <div id="clockDiv"></div>  <script>    
>> let clockEl = document.getElementById("clockDiv");    function 
>> getClockTime() {      let date = new Date();      let hr = 
>> date.getHours();      let min = date.getMinutes();      let sec = 
>> date.getSeconds();      hr = ("0" + hr).slice(-2);      min = ("0" + 
>> min).slice(-2);      sec = ("0" + sec).slice(-2);      clockEl.innerHTML = 
>> `${hr}:${min}:${sec}`;    }    setInterval(getClockTime, 1000);  
>> </script></body>]] }}}*>*
>> *<iframe* srcdoc=*<<vSrcDoc>>* style="border:none;width:100%;"
>> *></iframe>*
>> *</$vars>*
>>
>> Sneaky sneaky, has me wondering what kind of other fun things could be 
>> done...
>>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/0e0815a0-4c36-4808-99ce-cda170687a14n%40googlegroups.com.

Attachment: TwRandomFromCsvList.json
Description: application/json

Reply via email to