How to Change Browser Title Dynamically (v2021)

Tips submitted by PHPMaker users
Post Reply
mobhar
User
Posts: 11660

How to Change Browser Title Dynamically (v2021)

Post by mobhar »

If you want to change the browser's title dynamically by using the current page title, then this trick is for you. Simply set a client variable by using Page_Rendering server event, after that display it by using Client Script that belongs to all pages.

For example, when we are visiting Sales by Category for 1997 page from PHPMaker Demo Project (for example), then the browser title will be changed to: Sales by Category for 1997 < PHPMaker Demo Project. That means, the format of browser title is: {PageTitle} < {BodyTitle}

  1. Put the following PHP code into Page_Rendering server event under Server Events -> Global -> All Pages:

    // set a client variable named Browser_Title by PageTitle and BodyTitle (project name)
    SetClientVar("Browser_Title", Language()->phrase(CurrentPage()->TableName) . " < " . Language()->projectPhrase("BodyTitle"));
  2. Put the following Javascript code into Client Script under Client Scripts -> Global -> Pages with header/footer:

    var Browser_Title = ew.vars.Browser_Title;
    document.title = Browser_Title;
  3. Make sure you have already re-generated ALL the script files.

  4. Done.


alex
User
Posts: 266

Post by alex »

Great, thanx!

For multi-language can be as:

SetClientVar("Browser_Title", Language()->TablePhrase(CurrentPage()->TableName, "TblCaption") . " < " . Language()->projectPhrase("BodyTitle"));

wungaz
User
Posts: 214

Post by wungaz »

Great, amazing - I managed to implement it on a record view. For example if open a record for a car BMW 5 Series - wanted to show the title of the car on the browser.

Table Specific>>View Page>>Page_DateRendering

SetClientVar("Browser_Title", $this->CarTitle->ViewValue." >> ".Language()->projectPhrase("BodyTitle"));

Amazing, wanted the feature so much


malsonique
User
Posts: 25

Post by malsonique »

Thanks for sharing this idea. It really helps! Especially when a user long click the arrows back and forth, the dynamic titles are like spotlights.


Post Reply