有没有更有效的方法来搜索 window.location.href?
window.location.href:http://www.example.com/6CATA/folder/file.html
我目前的代码是:
var searchWinHref = window.location.href;
if(searchWinHref.indexOf("/6CATA/") > -1) {
alert('6CATA is in the window.location.href');
}
哪个工作得很好,但我正在尝试学习在可能的情况下优化代码的方法,如果我需要在一个页面上执行几次,我很想知道是否有更有效的方法来做到这一点?
编辑:
为了澄清,我需要偶尔在 URL 中搜索不同的变体,例如:6CATA 和 6CATB 等。