Page 1 of 1

dynamic title

Posted: Tue Apr 11, 2006 4:34 am
by malcolmboston
Im looking to update the title of the page with a % complete of a script im running,

whats the simplest way of implementing it in JS, the JS function only needs to accept the number, PHP does the maths

edit: i ask, because ive neever learnt JS :?

Posted: Tue Apr 11, 2006 4:53 am
by asgerhallas
isn't it just

<script>
document.title='<?=$percent;?>%';
</script>

Posted: Tue Apr 11, 2006 10:11 am
by pickle
So you're loading a page that starts a php file executing. You then want to display the percentage that php file is complete, on your webpage. Is that correct?

This will definitely require Javascript - and likely something called xmlhttp. xmlhttp is a method for clients (read: browsers) to communicate with the server, after the page is loaded. You'll have to use that in order to get the updated % from the server. You can then put it in the title of your page with document.title as ~asgerhallas suggested.

Posted: Tue Apr 11, 2006 10:21 am
by asgerhallas
You could just echo out the javascript to the browser whenever the percent changes, and then flush(); It works, I've used it from time to time. The HTML won't look good though.

Posted: Tue Apr 11, 2006 10:34 am
by malcolmboston
<script>
document.title='<?=$percent;?>%';
</script>

worked a treat, very lightweight and simple, thanks