我有当前的脚本来修改网址栏中的链接(function() { 'use strict'; location.replace(location.href.replace("www.reddit.com", "old.reddit.com"));})();我希望它在运行脚本的其余部分之前检查URL是否包含单词“ old”。我该怎么做呢?
1 回答

饮歌长啸
TA贡献1951条经验 获得超3个赞
您可以old通过将URL视为普通字符串来检查单词的索引。
if(location.href.indexOf('old') > -1) {
// do something
}
就这么简单。
添加回答
举报
0/150
提交
取消