How to Hide or Display Page Titles Based on User Roles?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2024 09:38 PM
Hello everyone! May I ask if there is any way for me to hide or remove this Page title? I want it to only display for certain roles. If possible, please guide me on how to do it. Thank you!
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2024 11:58 PM
Hello @jasoncao
To hide or display the page title based on user roles, you can use the following script in your onLoad function:
function onLoad() {
setTimeout(function () {
var titleElement = document.getElementsByTagName('title')[0];
if (!g_user.hasRoles('itil', 'admin')) {
titleElement.text = ''; // Hide the title for users without specified roles
} else {
titleElement.text = 'Customer Service'; // Display the title for users with specified roles
}
}, 500);
}
Make sure to uncheck the isolate script checkbox in your client script configuration. This will allow DOM manipulation, enabling you to modify the page title based on user roles effectively. The use of `setTimeout` ensures that the entire document is loaded before we attempt to change the document title according to the user roles.
If this helps, please mark my solution as accepted and helpful!
Thanks and Regards,
Siddhesh Jadhav
 
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2024 01:32 AM
Thank you for your answer, I tried with the CSM portal, but it seems that it doesn't apply to the CSM portal. If possible, could you guide me on how to change the title on the CSM portal? Thank you.