Ok – the users might get some benefit because the title is now more appropriate.
The code, if you really need to do it is
But here’s my thought process
- Search Engines will only see the original title, not the revised title
- Search Engines will therefore see either a generic or a spammy version of the title and the user gets the cleaned up version
- If the title isn’t right in the first place can you be accused of cloaking?
Now, that’s a serious risk, cloaking, can you afford that allegation?
Simpler, I think, is to use the server side processes to set the title correctly before the page ever gets to the browser.
And I have to stop reading my server logs, but yes, people actually search Google for this information!