w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Proper way to add HTML to the page and access Jquery as well as the users current tab?

First off, you can probably drop the scary permissions in favor of the activeTab permission.

Second, to have jQuery you need to inject it yourself before your other script. Since injecting is asynchronous, make sure you chain it properly:

chrome.browserAction.onClicked.addListener(function(tab) {
    chrome.tabs.executeScript(tab.id, {file: "jquery.min.js"}, function(){
        chrome.tabs.executeScript(tab.id, {file: "bookmarklet.js"});
    });
});

Third, you probably want to generate the requisite HTML using jQuery in your content script, bookmarklet.js. Or at least store it there in a variable. It's easier to do it on the content script side, but if you have to do it in the background, you should check out Message Passing.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.