Answer the question
In order to leave comments, you need to log in
Why doesn't setBadgeText change under the if condition?
Hello.
I'm writing a small extension.
There was a need to change the text near the icon ( setBadgeText ) provided that there is an element with the class .red_nor
Actually, what did I do here.
Here is my manifest object
{
"manifest_version": 2,
"name": "MyApp",
"version": "1.0",
"description": "Description text",
"background_page": "background.html",
"browser_action": {
"name": "Manipulate DOM",
"default_icon": {
"38": "lock-icon.png",
"19": "icon.png"
}
},
"background": {
"scripts": ["background.js", "jquery.min.js"]
},
"content_scripts": [ {
"js": [ "jquery.min.js", "background.js" ],
"matches": [ "http://*/*", "https://*/*"]
}]
}
var succlass = ".red_nor";
if ($(succlass)) {
console.log("true");
chrome.browserAction.setBadgeText({text: "yeah"});
} else {
console.log("false");
}
Answer the question
In order to leave comments, you need to log in
You need to check like this $(succlass).length
:
Even if no object is found, a jquery object will be returned, which is always true.
I don’t know for sure, but if you have Jquery, then in background.js in if you need to write $("succlass"), not just $(succlass)
In general, it seems like I figured it out. The fact is that when writing an application, there is a certain hierarchy, i.e. there is a separate script that works with browser elements, and there is one that works with the content part of the site.
Respectively it is browser_action and content_scripts
Now there is a question. How to pull out the value value in the content form and insert this value into the url of the script that processes the browser element i.e. i have this code
xhr = new XMLHttpRequest();
xhr.open("GET", "http://example.ru/1466088862.4504/", true);
xhr.send(null);
xhr.onreadystatechange = function() {
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question