rejetto forum

file changed macro in combination with javascript

Guest · 11 · 5028

0 Members and 1 Guest are viewing this topic.

ge2001

  • Guest
Hi,
Maybe you can help me with this fragment:

Code: [Select]
<script language="JavaScript" type="text/javascript">
<!--
var active;
function f_ChatUpdate()
{
{{.if|{{.file changed|ge2001\chat\chat.txt.}}|
{:
Dummy=String(Math.random());parent.frames[1].location.replace("chat.txt"+'?'+Dummy);
:}
.}}
}
-->
</script>

</head>
<body onload="aktiv=window.setInterval('f_ChatUpdate()',3000);" onunload="window.clearInterval(aktiv);">

The chat updates always, even if the file isn't changed. That is the problem.

Thanks


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
i think you should start changing all the {{. in {.
and .}} in .}


ge2001

  • Guest
Hi,
thank you for the help, code corrected.
Maybe i don't understand the file changed macro.
If i edit the file chat.txt manualy with a text editor and save it no update occurs.

I remove the macros, only using the javascript:

Dummy=String(Math.random());parent.frames[1].location.replace("chat.txt"+'?'+Dummy);

Now again editing the file chat.txt manualy with a text editor and saving it the update works fine.

So, what is wrong in my way of thinking ?


Offline ge2001

  • Occasional poster
  • *
    • Posts: 28
  • What
    • View Profile
    • Ragazzi
Hi,
the main question for me is how to use macros inside a javascript function.
Is it possible ? Can somebody supply an example ?

That is what i like to do:

function f_ChatUpdate()
{
macros here ?
Dummy=String(Math.random());parent.frames[1].location.replace("chat.txt"+'?'+Dummy);
}


Thanks


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
@ge2001
The macros are as variables, they are estimated and replaced before sending to the browser, they do not appear any more in sources of the web page, the macro are the equivalent diverted from the php


Offline ge2001

  • Occasional poster
  • *
    • Posts: 28
  • What
    • View Profile
    • Ragazzi
Hi,
o.k, thank you Mars.

But why do the code in my first post don't work ?
Please read also my second post, simulating the change of the file chat.txt with a text editor.
It works only if i remove the macros.

Do you have an idea ?

Thank you


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
In the ideal, it would be necessary to use a flow rss to update only what is modified in the file txt, but it is outside my field of expertise.

On the other hand, the macro of the first comment does not still exist, that's why it cannot work :D

 ;)


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
problem is: you are mixing server-side and client-side scripting.
server-side is run just ONCE, and before the browser downloads the page.
so you wrote your script expecting at every javascript interval to get the {.file changed.} while it is actually executed ONCE, before any interval is initiated.
if you need to read the {.file changed.} value through javascript you'll have to use AJAX.


Offline ge2001

  • Occasional poster
  • *
    • Posts: 28
  • What
    • View Profile
    • Ragazzi
Ouh,
thank you very much for the information.
I'm wondering that that several macros in a javascript interval do not work like expected.
Yes it works once, that was just confusing me completly ...

Your statement is very usefull for me and maybe also for other.


Thanks rejetto


Offline ge2001

  • Occasional poster
  • *
    • Posts: 28
  • What
    • View Profile
    • Ragazzi

Offline r][m

  • Tireless poster
  • ****
    • Posts: 347
    • View Profile
Hi,
Easy chat attached.
Thanks for sharing  :)
It works, but it adds many entries to the log quickly.
Needs [.....|no log] added.