I try to use jQuery and jQuery-UI in my Chrome extension. I try to create in the content script dialog window each time new tab is created but I keep getting:
Property '$' of object [object Window] is not a function
I guess I'm doing something wrong loading the scripts. Here's what I have:
{
"name":"Sample",
"description":"This is a sample",
"manifest_version":2,
"version":"2",
"background":{
"scripts":["background.js"]
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["jquery-1.8.3.min.js","jquery-ui.js","client.js","myscript.js"]
"run_at":"document_end",
"all_frames": true
}
],
"web_accessible_resources": [
"client.js","jquery-1.8.3.min.js","jquery-ui.js"
],
"permissions": [
"unlimitedStorage",
"http://*/",
"<all_urls>",
"tabs"
]
}
myscript.js ( the content script ):
var ss = document.createElement('script');
ss.type = "text/javascript";
ss.src = chrome.extension.getURL('jquery-1.8.3.min.js');
ss.onload = function() {
ss.parentNode.removeChild(ss);
console.log("jquery-1.8.3.min.js loaded");
};
var ss_ui = document.createElement('script');
ss_ui.type = "text/javascript";
ss_ui.src = chrome.extension.getURL('jquery-ui.js');
ss_ui.onload = function() {
ss_ui.parentNode.removeChild(ss_ui);
console.log("jquery-ui.js loaded");
};
var s = document.createElement('script');
s.type = "text/javascript";
s.src = chrome.extension.getURL('client.js');
s.onload = function() {
s.parentNode.removeChild(s);
console.log("client.js loaded");
};
try{
(document.head||document.documentElement).appendChild(ss);
(document.head||document.documentElement).appendChild(ss_ui);
(document.head||document.documentElement).appendChild(s);
}catch(e){
console.log("exception in appendChild");
}
client.js ( where I create the dialog )
try{
console.log("Starting to create tabel");
var layerNode= document.createElement('div');
layerNode.setAttribute('id','dialog');
layerNode.setAttribute('title','Basic dialog');
var pNode= document.createElement('p');
pNode.innerHTML = "This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.";
layerNode.appendChild(pNode);
document.body.appendChild(layerNode);
jq162 = jQuery.noConflict(true);
(function($){
$(document).ready(function() {
$("#dialog" ).dialog();
});
})(jq162);
}
catch(e){
console.log("script in page exception in appendChild"+e);
//alert(e);
}
when I see in the console to see the order of prints im getting :
Starting to create tabel client.js:2
script in page exception in appendChildTypeError: Cannot call method 'dialog' of null client.js:26
client.js loaded chrome-extension://mmoccjinakdjcmhjdjghhjnihbfkkgkp/myscript.js:24
jquery-1.8.3.min.js loaded chrome-extension://mmoccjinakdjcmhjdjghhjnihbfkkgkp/myscript.js:6
jquery-ui.js loaded
What am I doing wrong here?