character encoding - Chrome extension: Get charset of current page -


how can tell within background code charset current page defined.

more specifically: i'm using context menu , want know whether selected text encoded in utf-8 or not.

you can't without content scripts, can minimal permissions using activetab , chrome.tabs.executescript. this:

manifest.json

"permissions": [   "activetab","contextmenus" ], "background": {   "scripts": ["background.js"] } 

background.js

chrome.contextmenus.onclicked.addlistener(function(info, tab) {   chrome.tabs.executescript(tab.id,     {code:"function getcharset(){return document.charset;}getcharset();"},     function(results){        // results[0] contain charset page in question     }); }); 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -