rejetto forum

Software => HFS ~ HTTP File Server => HTML & templates => Topic started by: ge2001 on August 17, 2010, 08:49:47 PM

Title: file changed macro in combination with javascript
Post by: ge2001 on August 17, 2010, 08:49:47 PM
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
Title: Re: file changed macro in combination with javascript
Post by: rejetto on August 17, 2010, 09:55:49 PM
i think you should start changing all the {{. in {.
and .}} in .}
Title: Re: file changed macro in combination with javascript
Post by: ge2001 on August 18, 2010, 10:58:13 AM
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 ?
Title: Re: file changed macro in combination with javascript
Post by: ge2001 on August 20, 2010, 09:40:28 AM
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
Title: Re: file changed macro in combination with javascript
Post by: Mars on August 20, 2010, 06:45:52 PM
@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
Title: Re: file changed macro in combination with javascript
Post by: ge2001 on August 20, 2010, 07:54:37 PM
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
Title: Re: file changed macro in combination with javascript
Post by: Mars on August 20, 2010, 08:34:43 PM
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

 ;)
Title: Re: file changed macro in combination with javascript
Post by: rejetto on August 25, 2010, 11:25:43 PM
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 (http://en.wikipedia.org/wiki/Ajax_%28programming%29).
Title: Re: file changed macro in combination with javascript
Post by: ge2001 on August 26, 2010, 09:41:52 PM
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
Title: Re: file changed macro in combination with javascript
Post by: ge2001 on August 28, 2010, 01:45:24 PM
Hi,
Easy chat attached.
Title: Re: file changed macro in combination with javascript
Post by: r][m on August 28, 2010, 09:22:27 PM
Hi,
Easy chat attached.
Thanks for sharing  :)
It works, but it adds many entries to the log quickly.
Needs [.....|no log] added.