# Easily manage browser tab titles for all pages

**URL:** <https://forums.knack.com/t/easily-manage-browser-tab-titles-for-all-pages/13661>\
**Category:** Show & Tell\
**Created:** [January 18, 2023, 8:25pm UTC](https://forums.knack.com/t/easily-manage-browser-tab-titles-for-all-pages/13661 "2023-01-18T20:25:39Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryannn](https://avatars.discourse-cdn.com/v4/letter/r/74df32/32.png) [@Ryannn](https://forums.knack.com/u/Ryannn)\
**Post date:** [January 18, 2023, 8:25pm UTC](https://forums.knack.com/t/easily-manage-browser-tab-titles-for-all-pages/13661/1 "2023-01-18T20:25:39Z")

</div>

I’ve created a new way to set the title of your browser tab depending on the current scene. The nice thing is it keeps all of the code together, rather than spread out in the various `scene-render` events throughout your code. And since events can have multiple handlers you don’t need to worry about this overwriting any existing `scene-render` code you have elsewhere.

In the code below `scene_titles` uses scene number for the key, and tab title for the value. And you can have dynamic text by making the value a function.

```auto
const scene_titles = {
    "50": "Some Page",
    "55": "Another Page",
    "60": function() {
        let record_name = Knack.models["view_123"]["attributes"]["field_456"];
        return "View Record - " + record_name;
    },
};

for (const [scene_num, tab_title] of Object.entries(scene_titles)) {
    $(document).on("knack-scene-render.scene_" + scene_num, function(event, scene) {
        if (typeof tab_title == "function") {
            document.title = tab_title();
        }
        else {
            document.title = tab_title;
        }
    });
}

```

I imagine some folks prefer having each `scene-render` begin with assigning `document.title` as a way to track which scene it is. But I have quite a few scenes in my app and many don’t need custom code besides the tab title.

---

<div class="post-metadata">

**Author:** ![KnackPros](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/knackpros/32/807_2.png) [@KnackPros](https://forums.knack.com/u/KnackPros)\
**Post date:** [January 18, 2023, 9:38pm UTC](https://forums.knack.com/t/easily-manage-browser-tab-titles-for-all-pages/13661/2 "2023-01-18T21:38:36Z")

</div>

I agree—I’ve started writing my handlers dynamically (as shown) whenever possible and it definitely feels cleaner than seeing `scene-render` a bunch of times.

---

<div class="post-metadata">

**Author:** ![NormandDefayette\_CortexRD](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/normanddefayette_cortexrd/32/855_2.png) [@NormandDefayette\_CortexRD](https://forums.knack.com/u/NormandDefayette_CortexRD)\
**Post date:** [January 18, 2023, 9:44pm UTC](https://forums.knack.com/t/easily-manage-browser-tab-titles-for-all-pages/13661/3 "2023-01-18T21:44:47Z")

</div>

Hi guys,

That’s something I added to the KTL about 2 years ago. To bad nobody noticed ☹

Here’s the piece of code that does it:

```auto
            if (prevScene !== scene.key) {
                var menu = ktl.core.getMenuInfo().menu;
                (ktl.core.getCfg().enabled.showMenuInTitle && menu) && (document.title = Knack.app.attributes.name + ' - ' + menu); //Add menu to browser's tab.
...
                prevScene = scene.key;
            }

```

Go see the full code and documentation here - free and open source!  
**[Knack Toolkit Library - on GitHub](https://github.com/cortexrd/Knack-Toolkit-Library)**

Cheers,  
Normand

---

<div class="post-metadata">

**Author:** ![KnackPros](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/knackpros/32/807_2.png) [@KnackPros](https://forums.knack.com/u/KnackPros)\
**Post date:** [January 18, 2023, 10:59pm UTC](https://forums.knack.com/t/easily-manage-browser-tab-titles-for-all-pages/13661/4 "2023-01-18T22:59:43Z")

</div>

Hi Normand,

Thanks for sharing. Sometimes loading a library is overkill when a snippet will do, but in any case, it definitely looks cool, and great that you made it open-source.

Cheers

---

<div class="post-metadata">

**Author:** ![Dean2](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@Dean2](https://forums.knack.com/u/Dean2)\
**Post date:** [January 19, 2023, 1:38am UTC](https://forums.knack.com/t/easily-manage-browser-tab-titles-for-all-pages/13661/5 "2023-01-19T01:38:11Z")

</div>

Hi Normand

I agree with KnackPros.

I’d suggest you serve us tasty morsels, like this, 1 spoonful at a time. It’s easier for us non-coders to digest/comprehend.

---

<div class="post-metadata">

**Author:** ![Ryannn](https://avatars.discourse-cdn.com/v4/letter/r/74df32/32.png) [@Ryannn](https://forums.knack.com/u/Ryannn)\
**Post date:** [January 19, 2023, 2:55pm UTC](https://forums.knack.com/t/easily-manage-browser-tab-titles-for-all-pages/13661/6 "2023-01-19T14:55:41Z")

</div>

FWIW Normand I took a look at your library and think it could be useful for a large company/application. I really like the idea of grabbing local files to make development much faster. It always feels weird copying+pasting a few hundred/thousand lines of code into Knack.

---

<div class="post-metadata">

**Author:** ![BradStevens](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/bradstevens/32/140_2.png) [@BradStevens](https://forums.knack.com/u/BradStevens)\
**Post date:** [January 23, 2023, 3:11am UTC](https://forums.knack.com/t/easily-manage-browser-tab-titles-for-all-pages/13661/7 "2023-01-23T03:11:56Z")

</div>

Thanks for sharing @Ryannn!

---

<div class="post-metadata">

**Author:** ![NormandDefayette\_CortexRD](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/normanddefayette_cortexrd/32/855_2.png) [@NormandDefayette\_CortexRD](https://forums.knack.com/u/NormandDefayette_CortexRD)\
**Post date:** [January 24, 2023, 1:40pm UTC](https://forums.knack.com/t/easily-manage-browser-tab-titles-for-all-pages/13661/8 "2023-01-24T13:40:17Z")

</div>

@Dean2 You’re absolutely right, and I know that this is the reason why no one seems to be interested in the KTL. It’s like killing a mosquito with a light saber!

But I’ve just completed a **major simplification process** : it’s now only **5 lines of Javascript** code to copy, and no more CSS. All the complexity is hidden, yet visible to those who want to see the code. The minified code is currently at 125KB with an average load time around 200ms, which is quite negligible imo.

When I compare the minified/formatted Javascript code from Knack vs KTL, they have **137090** lines of code vs **4300** lines for the KTL - a drop in the bucket. They also use several libraries, like jQuery, FullCalendar, Highcharts, Sortable, Backbone, Moment, Bootstrap, Underscore, Lodash, Vue and more. So KTL would be just a small one among several others.

Usually, people are only interested in one or two features of the KTL, but once it’s installed and they see all what they get, I’m sure they will enjoy them. It not, it’s possible to turn off whatever you don’t like.

Cheers,  
Norm

---

<div class="post-metadata">

**Author:** ![AnthonySar57194](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@AnthonySar57194](https://forums.knack.com/u/AnthonySar57194)\
**Post date:** [July 5, 2023, 11:33am UTC](https://forums.knack.com/t/easily-manage-browser-tab-titles-for-all-pages/13661/9 "2023-07-05T11:33:44Z")

</div>

Does anyone know how to get this bit of code to work? I assume you can’t just copy and paste it into the Javasript section, I tried this and it had no effect on the name of the tabs in the browser. Thanks Anthony

---

<div class="post-metadata">

**Author:** ![Ryannn](https://avatars.discourse-cdn.com/v4/letter/r/74df32/32.png) [@Ryannn](https://forums.knack.com/u/Ryannn)\
**Post date:** [July 6, 2023, 12:14pm UTC](https://forums.knack.com/t/easily-manage-browser-tab-titles-for-all-pages/13661/10 "2023-07-06T12:14:41Z")

</div>

Hey @AnthonySar57194, you’ll need to update the scene numbers to ones relevant to your app. Start by opening Knack’s builder and going to the page/scene that you want a new title for. The browser URL for that page will look something like [https://builder.knack.com/](https://builder.knack.com/) your\_account/your\_app/pages/scene\_123. The number at the end is what you need. Then update the code so that `scene_titles` includes the scene number as a key and the title as the value.

```javascript
const scene_titles = {
    "123": "My page title",
}

```

---

<div class="post-metadata">

**Author:** ![NormandDefayette\_CortexRD](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/normanddefayette_cortexrd/32/855_2.png) [@NormandDefayette\_CortexRD](https://forums.knack.com/u/NormandDefayette_CortexRD)\
**Post date:** [July 6, 2023, 2:20pm UTC](https://forums.knack.com/t/easily-manage-browser-tab-titles-for-all-pages/13661/11 "2023-07-06T14:20:08Z")

</div>

Hi guys,

I’ve extracted the essential code from the KTL that shows the page title in the browser’s tab. It works across the whole app.

Here’s what it looks like:

```auto
$(document).on('knack-scene-render.any', function (event, scene) {
    const pageStr = Knack.scenes._byId[Knack.router.current_scene].attributes.name;
    document.title = Knack.app.attributes.name + ' - ' + pageStr; //Add menu to browser's tab.
})

```

Enjoy,  
Norm

---

<div class="post-metadata">

**Author:** ![AnthonySar57194](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@AnthonySar57194](https://forums.knack.com/u/AnthonySar57194)\
**Post date:** [July 10, 2023, 5:27pm UTC](https://forums.knack.com/t/easily-manage-browser-tab-titles-for-all-pages/13661/12 "2023-07-10T17:27:01Z")

</div>

Thanks perfect hat works!

---

<div class="post-metadata">

**Author:** ![Kombo](https://avatars.discourse-cdn.com/v4/letter/k/8e7dd6/32.png) [@Kombo](https://forums.knack.com/u/Kombo)\
**Post date:** [July 30, 2023, 9:44am UTC](https://forums.knack.com/t/easily-manage-browser-tab-titles-for-all-pages/13661/13 "2023-07-30T09:44:27Z")

</div>

Hi Normand!

Thank you soo much this worked so beautifully!

---

<div class="post-metadata">

**Author:** ![James10](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@James10](https://forums.knack.com/u/James10)\
**Post date:** [July 16, 2024, 11:05am UTC](https://forums.knack.com/t/easily-manage-browser-tab-titles-for-all-pages/13661/14 "2024-07-16T11:05:21Z")

</div>

Norm,  
I know this is not the place for this But…

I like the KTL code you have put together but I have a issue. On a Iphone if you have a numbers field it goes to the number keyboard on the Iphone and their is no decimal. Can this be turned off?

I look threw all you get hub stuff and can not seem to figure it out.

We have a Maintenance program built in knack with Technicians in the field using their phones. But staff in the back that really could benefit from KTL. But Time is money and in are case a decimal point is important.

Again sorry for asking here. I tried Get Hub but it never seemed to get across. I probably did something wrong . Saw you had a recent post here so just going for it.  
Thanks

---

<div class="post-metadata">

**Author:** ![NormandDefayette\_CortexRD](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/normanddefayette_cortexrd/32/855_2.png) [@NormandDefayette\_CortexRD](https://forums.knack.com/u/NormandDefayette_CortexRD)\
**Post date:** [July 16, 2024, 3:22pm UTC](https://forums.knack.com/t/easily-manage-browser-tab-titles-for-all-pages/13661/15 "2024-07-16T15:22:02Z")

</div>

Hi @James10,

No problem, this can be fixed easily by unchecking this flag in the KTL Configurator.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/knack/original/2X/7/7965c7c429b0436d53879ceaad2ac5d15ba0f3af.jpeg)

This will revert to default style in numeric fields.

You can also copy this snippet in the Builder if that’s easier for you:

```auto
ktl.fields.setCfg({
    convertNumToTel: false,
})

```

Be sure to add it at the right place! Above the last curly bracket.

See these two videos from Carl Holmes for more details on how to use the KTL Configurator:

[![](https://us1.discourse-cdn.com/flex020/uploads/knack/original/2X/2/2e31810dede897069e6b647925b2d0e80b1c08db.jpeg "Setting up the Configurator") ](https://www.youtube.com/watch?v=2_vVcIhdRlo)

[![](https://us1.discourse-cdn.com/flex020/uploads/knack/original/2X/c/c5c9217247e7f71d914e72be17ae5c271f7fcd26.jpeg "My Bad! Fixing Code Mistake & Cool KTL Updates 🚀") ](https://www.youtube.com/watch?v=R50bsGDAeOQ)

Cheers,  
Norm

---

<div class="post-metadata">

**Author:** ![James10](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@James10](https://forums.knack.com/u/James10)\
**Post date:** [July 16, 2024, 3:30pm UTC](https://forums.knack.com/t/easily-manage-browser-tab-titles-for-all-pages/13661/16 "2024-07-16T15:30:54Z")

</div>

Norm

You are a Scholar and a Gentleman

I appreciate you very much and Thanks.
