I have created a news feed script which automatically informs the user when new news items are available, like on twitter. I want to add this alert to the title so used this;
var originalTitle = document.title;
document.title = '(' + result + ') ' + originalTitle;
Now I don’t see the problem but it appends the result value before the originalTitle which would be fine if it wasn’t costantly being updated whenever there’s new news.
E.g; If 1 story is added and not another for a long time you get this;
(1) (1) (1) (1) (1) (1) title
E.g 2; If stories keep on getting added you get this;
(5) (4) (3) (2) (1) title
Not pretty. I want the while title to be rewritten each time and not just have the result appended infront each time.
It looks like
originalTitleis being over-written each time with whatever happens to be the title at the moment, which is why you’re winding up with(5) (4) ... titleJust save the original title in one place, with the line of code you already have.
Call that line in your document.ready handler, and leave it alone. Then each time you want to update the title, this should do what you want