“否则,如果”条件无法在Chrome扩展程序中运行

时间:2014-01-02 21:40:55

标签: javascript google-chrome google-chrome-extension gmail

我正在尝试根据选择的类型为Chrome扩展程序设置不同的操作。也许我正在阅读文档错误,但我无法弄清楚这里有什么不起作用。

的manifest.json

{
   "background": {
      "scripts": [ "background2.js" ]
   },

   "description": "Creates a context menu option which copies the selected address into a new Gmail compose window.",

   "manifest_version": 2,
   "name": "New Gmail Window",
   "permissions": [ "tabs", "contextMenus" ],
   "version": "0.1"
}

background.js

chrome.contextMenus.create({
            title: "Send a New Email",
            contexts:["link", "selection"],
            onclick: checkType,
        });

   function checkType(info,tab) { 
        if (info.linkUrl.substring(0, 7) === "mailto:") {     //The "if" works as expected // 
            chrome.windows.create({
                url:"https://mail.google.com/mail/?ui=2&view=cm&fs=1&tf=1&shva=1&to=" +info.linkUrl.substr(7),
                width:640,
                height:700,
                focused:true,
                type:"popup",
            });
            console.log("The linked emails work");
        }
        else if (info.selectionText.containsNode('a',false)) { //I want to look for an <a> tag that isn't working
            console.log("this worked");
        }
        else console.log("nothing to send");
    }

感谢您的帮助。

0 个答案:

没有答案