Is there a way to refresh a tiddler every time I click on a link? I have an iframe in a lot of my tiddlers that utilizes JavaScript that I need to run every time I return to that tiddler. I had this working on TWC. My plan is to bring my project over to TW5, but getting the feeling it may not be possible. Or is there a way to at least have the iframe refresh when I go back to that tiddler?
Hello @RedAsset
The problem you address here seems to be refreshing Iframes in tiddlers. As far as I know, the IFrame is not refreshed as logn as it is visible, even if the tiddler is refreshed.
Perhaps you need to build a macro out of this Toolbox: javascript - What’s the best way to reload / refresh an iframe? - Stack Overflow
I am sure there is a way to do this; in fact I have had the opposite problem, The Iframe refreshing when I don’t want it to.
I believe any change to the tiddler will force it to refresh so if you had;
- A refresh button that set a touch date / timestamp on the tiddler containing the iframe it may happen.
- Depending on how you get to the tiddler
- close and open navigating to it again may do it.
- You may be able to use message catcher to action a refresh with any navigation to the tiddler. It all depends on how you return to the tiddler.
I am confident this can be solved and I suggest its not sufficient an issue for you to not stick with tiddlywiki.
Open/Close works. The problem I am having is when it is already open, like you said that might be the case. Suppose there was a way to close a tiddler when opening another. I heard of Single Tiddler Mode, but I haven’t seen any recent news on this subject. I feel that would solve the problem. I don’t want to quit TW5 as it is way better than TWC.
To “auto-refresh” the content of a tiddler, how about wrapping the content with a list widget that gets the latest value in a tiddler that is updated by a timer event?
Take a look at this TiddlyWiki and see if there is anything in there that could be of use. Two samples on the Home tiddler:
- iframe that is auto-refreshed
(note the sucker is refreshing every second, as per the setup of my timer; you likely would not want such a quick refresh cycle, especially for big web pages) - just regular wikitext that is auto-refreshed
I tried something like this in the external.html file.
I am trying to do is scroll to a specific point in the external file every time I return to the tiddler. I put that timer in the external file, but then I am unable to scroll very far without it returning, and I am unable to cancel the timer.
This is what I have in the external file:
function scroll() {
var loc = window.location.href.split("?");
tiddler_id = loc[1]
document.getElementById(tiddler_id).style.borderLeft = '2px solid yellow';
document.getElementById(tiddler_id).style.borderRight = '2px solid yellow';
document.getElementById(tiddler_id).scrollIntoView({behavior: 'auto', block: 'center'});
setTimeout(scroll, 1000);
}
scroll();
// This is to stop setTimeout, but doesn't work.
window.addEventListener('scroll', noScroll);
function noScroll(){
clearTimeout(scroll);
}
EDIT: I think I figured it out. See next post.
Apologies, but I don’t understand what it is you are trying to do.
What I’ve given in the samples is a way to refresh a tiddler automatically.
That works fine.
What I don’t understand is what you mean by “click on a link”.
What kind of link, and where is it?
- Is it a wiki link to a tiddler in the TiddlyWiki?
- Is is a link in the TiddlyWiki to some other web site ?
- Is it a link that is inside of an iframe to some other web site?
- Other ?
In the timer event, put the value of <<currentTiddler>>
to SessionStorage.
Have your content in the iframe check SessionStorage regularly to see what the “current tiddler” is.
Have the content in the iframe scroll to the spot that makes sense for the current tiddler?
Useful tiddlers for session storage:
Apparently, the solution is easier than I thought.
I was able to do what I want with this code:
<$button>
<$action-sendmessage $message="tm-close-tiddler"/>
<$action-navigate $to="{{!!link-title}}"/>
{{!!link-title}}
</$button>
It would be if this could be done globally.
However, this also needs to be done from within the external HTML file as well.
Is there a way to send the “tm-close-tiddler” message from the outside?
Or better yet, a transcluded tiddler that I can use the “.scrollIntoView();” ability? This question would probably be better asked on another topic.
Anyway, I found this solution here: https://tiddlywiki.narkive.com/bsj7MauR/tw5-close-tiddler-open-tiddler-on-button-press.