jQuery:多个 "window.location.href" 不工作

jQuery: multiple "window.location.href" not working

我正在使用多个 window 位置选择器。我正在寻找的结果是一个测试警报弹出窗口。我不确定我做错了什么。我在 GreaseMonkey 中使用它。

// ==UserScript==
// @name        b
// @namespace   d
// @description b
// @include     *www.*
// @include     http://*
// @include     https://*
// @version     1
// @grant       none
// @require     http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js
// ==/UserScript==

$(document).ready(function () 
{ if(   (!window.location.href("https://www.youtube.com") > -1)  
       & (!window.location.href("https://www.google.com") > -1)    
    )   
{   

alert("I am an alert box!");

}
});

您的代码中有两个问题:

1) 条件语句错误 & 应该是 &&

2) 您还需要使用 indexOf 在 href 中查找所需 uri 的索引:

  if((!window.location.href.indexOf("https://www.youtube.com") > -1)  
     && (!window.location.href.indexOf("https://www.google.com") > -1)    
  )