我有情况我必须对css文件进行一些更改并重新加载它我已经完成了这个但浏览器需要刷新以反映这些更改请帮助
$.ajax({
type: "POST",
url: "handlers/load-css-file.ashx",
data: { colorCode: colorCode, defaultColor: defaultColor,currentCss:currentCss },
dataType: 'text',
async: false,
success: function () {
_edSite.theme = currentCss;
edLoadCss(_workUrl + _edSite.theme);
},
error: function () {
alert("Please try after some time.");
}
});
//loading css file on the website
function edLoadCss(href) {
var cssLink = $("<link rel='stylesheet' type='text/css' href='" + href + "'>");
$("head").append(cssLink);
};
我不想为此重新加载浏览器。
答案 0 :(得分:0)
试试这段代码:
$.ajax({
type: "POST",
url: "handlers/load-css-file.ashx",
data: { colorCode: colorCode, defaultColor: defaultColor,currentCss:currentCss },
dataType: 'text',
async: false,
success: function () {
_edSite.theme = currentCss;
edLoadCss(_workUrl + _edSite.theme);
},
error: function () {
alert("Please try after some time.");
}
});
//loading css file on the website
function edLoadCss(href) {
var d = new Date();
$("link [rel=stylesheet]").attr("href", href + "?" + d.getTime());
};