开发者

How to remove portions of Web page title using Javascript [duplicate]

This question already has answers here: How can I modify the title of a site using JavaScript? (2 answers) Closed 3 years ago.

I'm new at this Javascript stuff, so please excuse my basic question. I'm trying to find a way to remove some portion of a web page title using Javascript in a userscript. Take for example the title of this page:

How to remove portions of Web page title using Javascript - Stack Overflow

I want to yank out the '-' and Website name so that it becomes:

How to remove portions of We开发者_JAVA技巧b page title using Javascript

I know how to change the entire title using document.title = "new title";, but that's about the closest I can get. Can someone please help?

Thanks in advance.


This should do it:

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

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜