我注入css的chrome扩展不起作用
My chrome extension to inject css wont work
我正忙于开发chrome扩展。
它将做什么:
-
从PHP页面(XMLHttpRequest)获取数据
-
使用.Split 拆分结果变量
-
当有人点击div时,它会调用一个函数来插入一个css文件,该文件的名称是我在数字1中得到的。
我的问题:
当我点击那个按钮时什么也没发生。当我使用XMLHttpRequest中的变量"newvar"而不是变量"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);
}
});
window.user_data=user_data;//<-不需要。user_data=xmlhttp.responseText表示user_data对此窗口是全局的。window.currenttheme=currenttheme.toString()<lt;-不需要太
也向下数据[1]是一个字符串,因此替换
currenttheme = downdata[1].toString();
带有
currenttheme = downdata[1];
如果这没有帮助,请尝试alert(currenttheme);看看你是否得到了所需的主题名称,因为有时PHP会抛出错误并导致死亡,这可能不会产生"||||"。检查php输出并提醒xmlhttp.responseText查看是否一切正常。
相关文章:
- o数据扩展查询在SystemUserRolesSet上不起作用
- 正在处理在chrome扩展中不起作用的js
- 为什么这个扩展方法不起作用
- 为什么我的谷歌浏览器扩展程序在谷歌浏览器版本 41.0.2272.89 中不起作用
- Chrome 扩展程序权限不起作用
- Chrome 扩展 cookies.getAll 不起作用
- List.JS 在通过 Chrome 扩展程序注入时不起作用
- 设置Sails js视图扩展不'不起作用
- 使用jQuery的Chrome扩展不起作用
- chrome扩展名“sendResponse”不起作用
- 基本的谷歌chrome扩展消息传递不起作用
- $(document).click()在chrome扩展中不起作用
- Javascript在Google Chrome扩展的选项页中不起作用
- 在chrome扩展的弹出窗口中,警报不起作用
- firefox扩展对$.ajax的调用不起作用
- I'我试图制作一个chrome查找和替换扩展,但它赢了;不起作用
- chrome扩展弹出相同的选项卡仍然不起作用
- Javascript按钮单击在Chrome扩展弹出窗口中不起作用
- 从Ext.data.Store扩展不起作用
- 我注入css的chrome扩展不起作用