Invoke url in iframe with a button using JavaScript

75 views
Skip to first unread message

The Islander

unread,
Dec 25, 2019, 11:50:50 AM12/25/19
to tiddl...@googlegroups.com
Hi all,

On my TW5 I had a page inside an iframe in Tiddler1 (it's a dice roller). The iframe has an id of "myIframe".

The url inside the iframe can take parameter inputs like http://somewhere.com/myIframeRequest.html?param1=value0&param2=value1

I wanted one or more buttons in Tiddler2 to change the iframe url such as the following:

function myFunction(){
$('#myIframe').attr('src', "myIframeRequest.html?param1=value2&param2=value3"); 
} 

Any idea how I'd achieve that?

The use case is that inside the frame is a dice roller, and Tiddler2 is an info sheet that is interested in different dice rolls with a single click of a button.

Thanks!



The Islander

unread,
Dec 25, 2019, 5:40:52 PM12/25/19
to tiddl...@googlegroups.com
Another idea would be to implement a button whose action it is to overwrite the contents of the tiddler with the iframe.

But I'm not sure how I'd get a single button press to:
  1. Close Tiddler1
  2. Overwrite the contents of Tiddler1
  3. Open Tiddler1



Edit: or simply overwrite and refresh the tiddler.

The Islander

unread,
Dec 25, 2019, 8:32:03 PM12/25/19
to tiddl...@googlegroups.com
For the life of me I can't figure out how to concatenate a regular string with the contents of a tiddler and a variable inside a macro.

Let's say 'variable' = 35

Stringstuff{{$:/link/to/tiddler!!text}}$variable$

ends up with:

Stringstuff{{$:/link/to/tiddler!!text}}35

Any idea how to how to get the {{}} to evaluate? How do I concat these three things?

Even more frustrating is that if I put {{$:/link/to/tiddler!!text}} by itself in the macro it will evaulate just fine.

I'm also not able to put {{$:/link/to/tiddler!!text}} in its own macro and then:

Stringstuff<<new_macro>>$variable$

It just comes out as Stringstuff<<new_macro>>35


Eric Shulman

unread,
Dec 26, 2019, 12:42:41 AM12/26/19
to tiddl...@googlegroups.com
Despite their appearance, TW macros aren't functions.  That is, they don't "evaluate and return".

They are more "text expanders".  The only thing a macro does is to replace $param$ with the value passed to it,
and replace $(variable)$ with the value of the variable (only if it was defined *outside* the macro).

It is up to the "caller" of the macro to determine how it is rendered, if at all.  If the macro is invoked from wiki content,
then it is rendered, as if it had been typed right there; but, if the macro result is used as a parameter value for a widget
call, then it is not parsed, and it left up to the widget itself to use, as is.

So, for your purposes, to combine literal text and the contents of a tiddler, you could write something like this:
\define combined(paramstuff)
Stringstuff$(tiddlerstuff)$$paramstuff$
\end

and then invoke it like this:
<$vars tiddlerstuff={{$:/link/to/tiddler!!text}}>
<
<combined 35>>
</$vars>
The enclosing $vars widget retrieves the value from the tiddler contents
The scope of the variable is only within the enclosing <$vars>...</$vars> section

For the use-case you mentioned in your OP, something like this might do:

\define makeurl()
\end

<$edit-text field="value1" />
<$edit-text field="value2" />

<$vars value1={{!!value1}} value2={{!!value2}}>
URL src is: <<makeurl>><br>
<iframe src=<<makeurl>> />
</$vars>

Of course, you could put the edit-text widgets into a separate tiddler (e.g., Tiddler2)
and then reference them in the $vars, using {{Tiddler2!!value1}} and {{Tiddler2!!value2}}

Hopefully, the above example code is enough to get you started in the right direction...

Let me know how it goes.

enjoy,
-e
Eric Shulman






Reply all
Reply to author
Forward
0 new messages