1

如何在后台代码中判断当前页面是使用哪个字符集定义的。

更具体地说:我正在使用上下文菜单,我想知道所选文本是否以 utf-8 编码。

4

1 回答 1

3

没有 就无法做到这一点content scripts,但您可以使用activeTab和以最少的权限做到这一点chrome.tabs.executeScript。它看起来像这样:

清单.json

"permissions": [
  "activeTab","contextMenus"
],
"background": {
  "scripts": ["background.js"]
}

背景.js

chrome.contextMenus.onClicked.addListener(function(info, tab) {
  chrome.tabs.executeScript(tab.id,
    {code:"function getCharset(){return document.charset;}getCharset();"},
    function(results){
       // results[0] will now contain the charset for the page in question
    });
});
于 2013-05-09T02:17:14.867 回答