logo

NJP

Dynamic Browser Window Title

Import · May 01, 2013 · article

UPDATED: I've added some code for a few pages that are opened in a different tab/window (Workflow Editor, BSM/Schema Maps, etc...).

There are already a number of scripts out there to dynamically change the title of the browser's window/tab to match the current record you are looking at, but I thought I'd add my own anyways image

image

image

imageI've added a little bit of logic to verify if the record is a new one, or you are in a Search form, etc... You can also set the default title for all the other windows and it strips out the "undefined" string if the name, number or short_description fields are not on the form. To use it, just create a new UI Script, check the Active and Global checkboxes and drop in the following code:

addLoadEvent(u_setCustomTitle);function u_setCustomTitle(){ var title = "Custom Window Title"; var windowName = top.window.name.toLowerCase(); switch (windowName) { case "workflow": title="Workflow Editor"; break; case "show_workflow_context": title = "Running Workflow(s)"; break; case "super_bsm_map": title = "BSM Map"; break; case "super_schema": title = "Schema Map"; break; default: try { var name = g_form.getValue("name").replace("undefined",""); var number = g_form.getValue("number").replace("undefined",""); var shortDescription = g_form.getValue("short_description").replace("undefined",""); if ($("sysverb_query") != undefined) { title = "Search"; } else if (g_form.isNewRecord()) { title = "New Record"; } else if (name) { title = name; } else if (number && shortDescription) { title = number + " - " + shortDescription; } else if (number) { title = number; } else if (shortDescription) { title = shortDescription; } } catch(e) {} } top.document.title = title;

}

I've also attached an xml file that you can just import as well.

View original source

https://www.servicenow.com/community/in-other-news/dynamic-browser-window-title/ba-p/2275420