如何使用JavaScript修改网站标题? [英] How can I modify the title of a site using JavaScript?

查看:126
本文介绍了如何使用JavaScript修改网站标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看torrent页面时,选项卡的标题为:

When viewing a torrent page, the title of the tab is:

Bitsoup.org激流食欲的最佳网站::的详细信息 种子"ABC"

Bitsoup.org The Best site for your Torrent appetite :: Details for torrent "ABC"

其中"ABC"是种子文件的名称.

where "ABC" is the name of the torrent file.

不幸的是,当我打开3个以上的选项卡时,看不到种子文件的名称.

Unfortunately, when I have 3+ tabs open, I can not see what the name of the torrent file is.

我正在尝试创建一个Greasemonkey脚本来截断或拆分标题,以使其仅显示种子名称,而不显示开头部分.

I am attempting to create a Greasemonkey script to truncate, or split, the title, so that it only displays the torrent-name, and not the beginning part.

我知道您可以使用document.title = ...

但我不确定将其分配给什么.

but I am unsure of what to assign it to.

推荐答案

您可以使用正则表达式,也许:

You could use a regular expression, perhaps:

document.title = document.title.match(/"([^"]+)"/)[1]

此正则表达式使用分组来匹配引号之间的第一项内容,并将其分配给title(不带引号).

This regex uses grouping to matches the first thing that is between quotes, and assigns it to the title (without the quotes).

这篇关于如何使用JavaScript修改网站标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆