Page 1 of 1

How to Change Browser Title Dynamically (v2021)

Posted: Wed Dec 30, 2020 9:43 am
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.


Re: How to Change Browser Title Dynamically (v2021)

Posted: Mon Jan 04, 2021 8:00 am
by alex

Great, thanx!

For multi-language can be as:

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

Re: How to Change Browser Title Dynamically (v2021)

Posted: Sat Jan 09, 2021 2:56 am
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


Re: How to Change Browser Title Dynamically (v2021)

Posted: Mon Jun 21, 2021 1:45 pm
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.