クロムエクステンションを開発中です。それが何をするか私のクロムエクステンションは、仕事をしないでください。
:誰かがdiv要素をクリックしたときに
は
を.split使用してPHPページ(XMLHttpRequestの)
スプリットからの結果変数をデータを取得し、それは私が番号1に持っているその名前のCSSファイルを挿入する関数を呼び出すでしょう。
問題:
ボタンをクリックしても何も起こりません。これは、XMLHttpRequestの変数 "currenttheme"ではなく、変数 "newvar"を使用したときに機能します。私はそれを.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
* * IE6、IE5 *のコードは、実際にはクロムエクステンションの防御プログラミングです –