我正在忙於開發鉻擴展。我的Chrome擴展注入css不會工作
它的作用:
獲得從PHP頁面(XMLHttpRequest的)數據
分割使用.split
當有人點擊一個div結果變量,它會調用一個函數來插入一個名稱爲1的css文件。
我的問題:
好吧,當我點擊那個按鈕時沒有任何反應。它在我使用變量「newvar」而不是XMLHttpRequest中的變量「currenttheme」時起作用。我試着將它轉換爲字符串以及使用.toString。哦,提醒變量確實起作用,並給出與newvar完全相同的響應。
我的代碼:(嘆氣!)
//My XMLHttpRequest
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
user_data = xmlhttp.responseText;
window.user_data = user_data;
processdata();
}
}
xmlhttp.open("GET","http://localhost:8888/myphppage.php",true);
xmlhttp.send();
function processdata() {
//split result variable from PHP
var downdata = user_data.split('|||||');
var installedthemes = downdata[0];
currenttheme = downdata[1].toString();
window.currenttheme = currenttheme.toString();
}
function click(e) {
newvar = "001";
//insert css - works with variable newvar but not with this one
chrome.tabs.insertCSS(null,
{file:currenttheme + ".css"});
//alerting the variable works, exactly the same as newvar
alert (currenttheme);
}
document.addEventListener('DOMContentLoaded', function() {
var divs = document.querySelectorAll('div');
for (var i = 0; i < divs.length; i++) {
divs[i].addEventListener('click', click);
}
});
對您的問題更好的標題可能會幫助您獲得更多回復。 – itsmequinn 2012-02-17 17:51:35
現在*//代碼爲IE6,IE5 * *真的*防擴散鍍鉻擴展 – 2012-02-17 17:52:54