Jump to content

Can you append things to page title?


shortysbest

Recommended Posts

I have notifications that automatically update every so often, and i want it to append the amount of notifications in the page title. I have other information in the title such as site name, and page etc. How could I append the notifications to the title and keep the other information in the title.

Link to comment
https://forums.phpfreaks.com/topic/221418-can-you-append-things-to-page-title/
Share on other sites

Yeah. I got it working, however it had some problems. Since the script that updates it runs ever 10 or so seconds, it would append (1) every 10 or so seconds. And if i replace what's in the title it wouldnt show the site name, and the page and all of that. Just everything i tried it wouldn't work right.

I know what you mean. A possible solution would be to store the title within a global var as the page loads. Then whenever you update the page title, set it to the global var + the extra string. Quick example:

 

var g_page_title;

window.onload = function() {
    g_page_title = document.title;
}

function updateTitle(title) {
    document.title = g_page_title + title;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.