i am injecting various script's and css from chrome extension, below is my snippet code,
Background.js
function start() {
var tab = JSON.parse(localStorage.getItem('tab'));
chrome.tabs.insertCSS(tab.id, { file: 'assets/css/style.css' })
chrome.tabs.executeScript(tab.id, { file: 'assets/lib/jquery-1.8.2.min.js' }, function () {
chrome.tabs.executeScript(tab.id, { file: 'assets/lib/jquery-ui.min.js' }, function () {
chrome.tabs.executeScript(tab.id, { file: 'js/inject/inject.js'});
});
});
}
chrome.browserAction.onClicked.addListener(function (tab) {
start();
});
Inject.js
(function(){
jQuery(document).ready(function () {
console.log("Document Loaded!!");
jQuery("#Table td").click(function() {
var column_num = parseInt( $(this).index() ) + 1;
var row_num = parseInt( $(this).parent().index() )+1;
console.log(column_num, row_num);
});
});
})();
now the problem is that when i am opening extension second time jQuery stops working and throwing error of
Uncaught TypeError: jQuery is not a function
or
Uncaught TypeError: jQuery is undefined
I need to find if it is possible to check that my inject.js has already been executed then on reopening extension i just need to call other functions.