dynamic title

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

dynamic title

Post 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 :?
asgerhallas
Forum Commoner
Posts: 80
Joined: Tue Mar 14, 2006 11:11 am
Location: Århus, Denmark

Post by asgerhallas »

isn't it just

<script>
document.title='<?=$percent;?>%';
</script>
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
asgerhallas
Forum Commoner
Posts: 80
Joined: Tue Mar 14, 2006 11:11 am
Location: Århus, Denmark

Post 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.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

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

worked a treat, very lightweight and simple, thanks
Post Reply