How to remove part of a web page header using Javascript

I am new to this Javascript stuff, so please excuse my main question. I am trying to find a way to remove part of the title of a webpage using Javascript in usercript. Take for example the title of this page:

How to remove part of a web page header using Javascript - stack overflow

I want to pull out the name "-" and "Website" so that it becomes the following:

How to remove part of a web page header using Javascript

I know how to change the whole title using document.title = "new title";, but it's about the near I can get. Can anybody help?

Thanks in advance.

+3
source share
1 answer

This should do it:

document.title.substr(0,document.title.lastIndexOf("-"));

It removes everything from the last occurrence of a "-".

http://jsfiddle.net/niklasvh/TA69F/

+4
source

All Articles